Skip to content

Commit

Permalink
add connectors
Browse files Browse the repository at this point in the history
Signed-off-by: kalyan <[email protected]>
  • Loading branch information
rawwar committed Nov 24, 2023
1 parent c977981 commit 258128c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
59 changes: 59 additions & 0 deletions opensearch_py_ml/ml_commons/connectors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# SPDX-License-Identifier: Apache-2.0
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
# Any modifications Copyright OpenSearch Contributors. See
# GitHub history for details.

from opensearchpy import OpenSearch
from opensearch_py_ml.ml_commons.ml_common_utils import ML_BASE_URI


class Connectors:
def __init__(self, os_client: OpenSearch):
self.client = os_client

def create_standalone_connector(self, payload: dict):
if not isinstance(payload, dict):
raise ValueError("payload needs to be a dictionary")

return self.client.transport.perform_request(
method="POST", url=f"{ML_BASE_URI}/connectors/_create", body=payload
)

def create_internal_connector(self, payload: dict):
if not isinstance(payload, dict):
raise ValueError("payload needs to be a dictionary")

return self.client.transport.perform_request(
method="POST", url=f"{ML_BASE_URI}/models/_register", body=payload
)

def list_connectors(self):
search_query = {"query": {"match_all": {}}}
return self.search_connectors(search_query)

def search_connectors(self, search_query: dict):
if not isinstance(search_query, dict):
raise ValueError("search_query needs to be a dictionary")

return self.client.transport.perform_request(
method="POST", url=f"{ML_BASE_URI}/connectors/_search", body=search_query
)


def get_connector(self, connector_id: str):
if not isinstance(connector_id, str):
raise ValueError("connector_id needs to be a string")

return self.client.transport.perform_request(
method="GET", url=f"{ML_BASE_URI}/connectors/{connector_id}"
)

def delete_connector(self, connector_id: str):
if not isinstance(connector_id, str):
raise ValueError("connector_id needs to be a string")

return self.client.transport.perform_request(
method="DELETE", url=f"{ML_BASE_URI}/connectors/{connector_id}"
)
3 changes: 2 additions & 1 deletion opensearch_py_ml/ml_commons/ml_commons_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from opensearch_py_ml.ml_commons.model_access_control import ModelAccessControl
from opensearch_py_ml.ml_commons.model_execute import ModelExecute
from opensearch_py_ml.ml_commons.model_uploader import ModelUploader

from opensearch_py_ml.ml_commons.connectors import Connectors

class MLCommonClient:
"""
Expand All @@ -37,6 +37,7 @@ def __init__(self, os_client: OpenSearch):
self._model_uploader = ModelUploader(os_client)
self._model_execute = ModelExecute(os_client)
self.model_access_control = ModelAccessControl(os_client)
self.connectors = Connectors(os_client)

def execute(self, algorithm_name: str, input_json: dict) -> dict:
"""
Expand Down

0 comments on commit 258128c

Please sign in to comment.