Skip to content

Commit

Permalink
Add deepseek as a trusted endpoint. (opensearch-project#3440) (opense…
Browse files Browse the repository at this point in the history
…arch-project#3446)

Signed-off-by: Nathalie Jonathan <[email protected]>
(cherry picked from commit 06a6021)

Co-authored-by: Nathalie Jonathan <[email protected]>
  • Loading branch information
1 parent 758b963 commit 17251cd
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ private MLCommonsSettings() {}
"^https://api\\.sagemaker\\..*[a-z0-9-]\\.amazonaws\\.com/.*$",
"^https://api\\.openai\\.com/.*$",
"^https://api\\.cohere\\.ai/.*$",
"^https://api\\.deepseek\\.com/.*$",
"^https://bedrock-runtime\\..*[a-z0-9-]\\.amazonaws\\.com/.*$",
"^https://bedrock-agent-runtime\\..*[a-z0-9-]\\.amazonaws\\.com/.*$",
"^https://bedrock\\..*[a-z0-9-]\\.amazonaws\\.com/.*$",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ public class TransportCreateConnectorActionTests extends OpenSearchTestCase {
private ArgumentCaptor<PutDataObjectRequest> putDataObjectRequestArgumentCaptor;

private static final List<String> TRUSTED_CONNECTOR_ENDPOINTS_REGEXES = ImmutableList
.of("^https://runtime\\.sagemaker\\..*\\.amazonaws\\.com/.*$", "^https://api\\.openai\\.com/.*$", "^https://api\\.cohere\\.ai/.*$");
.of(
"^https://runtime\\.sagemaker\\..*\\.amazonaws\\.com/.*$",
"^https://api\\.openai\\.com/.*$",
"^https://api\\.cohere\\.ai/.*$",
"^https://api\\.deepseek\\.com/.*$"
);

@Before
public void setup() {
Expand Down Expand Up @@ -539,4 +544,57 @@ public void test_execute_URL_notMatchingExpression_exception() {
argumentCaptor.getValue().getMessage()
);
}

public void test_connector_creation_success_deepseek() {
TransportCreateConnectorAction action = new TransportCreateConnectorAction(
transportService,
actionFilters,
mlIndicesHandler,
client,
sdkClient,
mlEngine,
connectorAccessControlHelper,
settings,
clusterService,
mlModelManager,
mlFeatureEnabledSetting
);
doAnswer(invocation -> {
ActionListener<Boolean> listener = invocation.getArgument(0);
listener.onResponse(true);
return null;
}).when(mlIndicesHandler).initMLConnectorIndex(isA(ActionListener.class));

doAnswer(invocation -> {
ActionListener<IndexResponse> listener = invocation.getArgument(1);
listener.onResponse(indexResponse);
return null;
}).when(client).index(any(IndexRequest.class), isA(ActionListener.class));

List<ConnectorAction> actions = new ArrayList<>();
actions
.add(
ConnectorAction
.builder()
.actionType(ConnectorAction.ActionType.PREDICT)
.method("POST")
.url("https://api.deepseek.com/v1/chat/completions")
.build()
);

Map<String, String> credential = ImmutableMap.of("access_key", "mockKey", "secret_key", "mockSecret");
MLCreateConnectorInput mlCreateConnectorInput = MLCreateConnectorInput
.builder()
.name(randomAlphaOfLength(5))
.description(randomAlphaOfLength(10))
.version("1")
.protocol(ConnectorProtocols.HTTP)
.credential(credential)
.actions(actions)
.build();

MLCreateConnectorRequest request = new MLCreateConnectorRequest(mlCreateConnectorInput);
action.doExecute(task, request, actionListener);
verify(actionListener).onResponse(any(MLCreateConnectorResponse.class));
}
}

0 comments on commit 17251cd

Please sign in to comment.