Skip to content

Commit a083b32

Browse files
committed
fix conflicts
Signed-off-by: Pavan Yekbote <mail2pavanyekbote@gmail.com>
2 parents 83332ff + 17251cd commit a083b32

File tree

4 files changed

+87
-7
lines changed

4 files changed

+87
-7
lines changed

plugin/src/main/java/org/opensearch/ml/settings/MLCommonsSettings.java

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ private MLCommonsSettings() {}
167167
"^https://api\\.sagemaker\\..*[a-z0-9-]\\.amazonaws\\.com/.*$",
168168
"^https://api\\.openai\\.com/.*$",
169169
"^https://api\\.cohere\\.ai/.*$",
170+
"^https://api\\.deepseek\\.com/.*$",
170171
"^https://bedrock-runtime\\..*[a-z0-9-]\\.amazonaws\\.com/.*$",
171172
"^https://bedrock-agent-runtime\\..*[a-z0-9-]\\.amazonaws\\.com/.*$",
172173
"^https://bedrock\\..*[a-z0-9-]\\.amazonaws\\.com/.*$",

plugin/src/test/java/org/opensearch/ml/action/connector/TransportCreateConnectorActionTests.java

+51-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ public class TransportCreateConnectorActionTests extends OpenSearchTestCase {
123123
"^https://runtime\\.sagemaker\\..*\\.amazonaws\\.com/.*$",
124124
"^https://api\\.openai\\.com/.*$",
125125
"^https://api\\.cohere\\.ai/.*$",
126-
REKOGNITION_TRUST_ENDPOINT_REGEX
126+
REKOGNITION_TRUST_ENDPOINT_REGEX,
127+
"^https://api\\.deepseek\\.com/.*$"
127128
);
128129

129130
@Before
@@ -546,6 +547,55 @@ public void test_execute_URL_notMatchingExpression_exception() {
546547
);
547548
}
548549

550+
public void test_connector_creation_success_deepseek() {
551+
TransportCreateConnectorAction action = new TransportCreateConnectorAction(
552+
transportService,
553+
actionFilters,
554+
mlIndicesHandler,
555+
client,
556+
sdkClient,
557+
mlEngine,
558+
connectorAccessControlHelper,
559+
settings,
560+
clusterService,
561+
mlModelManager,
562+
mlFeatureEnabledSetting
563+
);
564+
doAnswer(invocation -> {
565+
ActionListener<Boolean> listener = invocation.getArgument(0);
566+
listener.onResponse(true);
567+
return null;
568+
}).when(mlIndicesHandler).initMLConnectorIndex(isA(ActionListener.class));
569+
doAnswer(invocation -> {
570+
ActionListener<IndexResponse> listener = invocation.getArgument(1);
571+
listener.onResponse(indexResponse);
572+
return null;
573+
}).when(client).index(any(IndexRequest.class), isA(ActionListener.class));
574+
List<ConnectorAction> actions = new ArrayList<>();
575+
actions
576+
.add(
577+
ConnectorAction
578+
.builder()
579+
.actionType(ConnectorAction.ActionType.PREDICT)
580+
.method("POST")
581+
.url("https://api.deepseek.com/v1/chat/completions")
582+
.build()
583+
);
584+
Map<String, String> credential = ImmutableMap.of("access_key", "mockKey", "secret_key", "mockSecret");
585+
MLCreateConnectorInput mlCreateConnectorInput = MLCreateConnectorInput
586+
.builder()
587+
.name(randomAlphaOfLength(5))
588+
.description(randomAlphaOfLength(10))
589+
.version("1")
590+
.protocol(ConnectorProtocols.HTTP)
591+
.credential(credential)
592+
.actions(actions)
593+
.build();
594+
MLCreateConnectorRequest request = new MLCreateConnectorRequest(mlCreateConnectorInput);
595+
action.doExecute(task, request, actionListener);
596+
verify(actionListener).onResponse(any(MLCreateConnectorResponse.class));
597+
}
598+
549599
public void test_connector_creation_success_rekognition() {
550600
TransportCreateConnectorAction action = new TransportCreateConnectorAction(
551601
transportService,

search-processors/src/main/java/org/opensearch/searchpipelines/questionanswering/generative/ext/GenerativeQAParameters.java

+21-6
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public class GenerativeQAParameters implements Writeable, ToXContentObject {
9090

9191
static final Version MINIMAL_SUPPORTED_VERSION_FOR_BEDROCK_CONVERSE_LLM_MESSAGES = CommonValue.VERSION_2_18_0;
9292

93+
public static final Version MINIMAL_SUPPORTED_VERSION_FOR_PROMPT_AND_INSTRUCTIONS = CommonValue.VERSION_2_13_0;
94+
9395
@Setter
9496
@Getter
9597
private String conversationId;
@@ -200,16 +202,23 @@ public GenerativeQAParameters(StreamInput input) throws IOException {
200202
this.llmQuestion = input.readString();
201203
}
202204

203-
this.systemPrompt = input.readOptionalString();
204-
this.userInstructions = input.readOptionalString();
205+
if (version.onOrAfter(MINIMAL_SUPPORTED_VERSION_FOR_PROMPT_AND_INSTRUCTIONS)) {
206+
this.systemPrompt = input.readOptionalString();
207+
this.userInstructions = input.readOptionalString();
208+
}
209+
205210
this.contextSize = input.readInt();
206211
this.interactionSize = input.readInt();
207212
this.timeout = input.readInt();
208-
this.llmResponseField = input.readOptionalString();
213+
214+
if (version.onOrAfter(MINIMAL_SUPPORTED_VERSION_FOR_PROMPT_AND_INSTRUCTIONS)) {
215+
this.llmResponseField = input.readOptionalString();
216+
}
209217

210218
if (version.onOrAfter(MINIMAL_SUPPORTED_VERSION_FOR_BEDROCK_CONVERSE_LLM_MESSAGES)) {
211219
this.llmMessages.addAll(input.readList(MessageBlock::new));
212220
}
221+
213222
}
214223

215224
@Override
@@ -272,12 +281,18 @@ public void writeTo(StreamOutput out) throws IOException {
272281
out.writeString(llmQuestion);
273282
}
274283

275-
out.writeOptionalString(systemPrompt);
276-
out.writeOptionalString(userInstructions);
284+
if (version.onOrAfter(MINIMAL_SUPPORTED_VERSION_FOR_PROMPT_AND_INSTRUCTIONS)) {
285+
out.writeOptionalString(systemPrompt);
286+
out.writeOptionalString(userInstructions);
287+
}
288+
277289
out.writeInt(contextSize);
278290
out.writeInt(interactionSize);
279291
out.writeInt(timeout);
280-
out.writeOptionalString(llmResponseField);
292+
293+
if (version.onOrAfter(MINIMAL_SUPPORTED_VERSION_FOR_PROMPT_AND_INSTRUCTIONS)) {
294+
out.writeOptionalString(llmResponseField);
295+
}
281296

282297
if (version.onOrAfter(MINIMAL_SUPPORTED_VERSION_FOR_BEDROCK_CONVERSE_LLM_MESSAGES)) {
283298
out.writeList(llmMessages);

search-processors/src/test/java/org/opensearch/searchpipelines/questionanswering/generative/ext/GenerativeQAParamExtBuilderTests.java

+14
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public void testMiscMethods() throws IOException {
121121
assertNotEquals(builder1, builder2);
122122
assertNotEquals(builder1.hashCode(), builder2.hashCode());
123123

124+
// BWC test for bedrock converse params
124125
StreamOutput so1 = mock(StreamOutput.class);
125126
when(so1.getVersion()).thenReturn(GenerativeQAParameters.MINIMAL_SUPPORTED_VERSION_FOR_BEDROCK_CONVERSE_LLM_MESSAGES);
126127
builder1.writeTo(so1);
@@ -130,6 +131,19 @@ public void testMiscMethods() throws IOException {
130131
when(so2.getVersion()).thenReturn(Version.V_2_17_0);
131132
builder1.writeTo(so2);
132133
verify(so2, times(5)).writeOptionalString(any());
134+
135+
// BWC test for system prompt and instructions
136+
StreamOutput so3 = mock(StreamOutput.class);
137+
when(so3.getVersion()).thenReturn(GenerativeQAParameters.MINIMAL_SUPPORTED_VERSION_FOR_PROMPT_AND_INSTRUCTIONS);
138+
builder1.writeTo(so3);
139+
verify(so3, times(5)).writeOptionalString(any());
140+
verify(so3, times(1)).writeString(any());
141+
142+
StreamOutput so4 = mock(StreamOutput.class);
143+
when(so4.getVersion()).thenReturn(Version.V_2_12_0);
144+
builder1.writeTo(so4);
145+
verify(so4, times(2)).writeOptionalString(any());
146+
verify(so4, times(1)).writeString(any());
133147
}
134148

135149
public void testParse() throws IOException {

0 commit comments

Comments
 (0)