-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding executeAPI Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * updating documentation Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * changing code and test Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * changing code Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * fixing tests Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * changing tests Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * checking output value in integration tests Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> --------- Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com>
- Loading branch information
1 parent
5fe401c
commit 8eb26eb
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Execute | ||
================== | ||
|
||
.. currentmodule:: opensearch_py_ml | ||
|
||
.. autofunction:: opensearch_py_ml.ml_commons.MLCommonClient.execute |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# 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. | ||
|
||
import json | ||
|
||
from opensearchpy import OpenSearch | ||
|
||
from opensearch_py_ml.ml_commons.ml_common_utils import ML_BASE_URI | ||
|
||
|
||
class ModelExecute: | ||
""" | ||
Class for executing algorithms using ML Commons execute API. | ||
""" | ||
|
||
API_ENDPOINT = "models/_execute" | ||
|
||
def __init__(self, os_client: OpenSearch): | ||
self._client = os_client | ||
|
||
def _execute(self, algorithm_name: str, input_json: dict) -> dict: | ||
""" | ||
This method executes ML algorithms that can be only executed directly (i.e. do not support train and | ||
predict APIs), like anomaly localization and metrics correlation. | ||
The input json must be a dictionary or a deserializable Python object. | ||
The algorithm has to be supported by ML Commons. | ||
Refer to https://opensearch.org/docs/2.7/ml-commons-plugin/api/#execute | ||
:param algorithm_name: Name of the algorithm | ||
:type algorithm_name: string | ||
:param input_json: Dictionary of parameters or a deserializable string, byte, or bytearray | ||
:type input_json: dict | ||
:return: returns the API response | ||
:rtype: dict | ||
""" | ||
|
||
if not isinstance(input_json, dict): | ||
input_json = json.loads(input_json) | ||
|
||
return self._client.transport.perform_request( | ||
method="POST", | ||
url=f"{ML_BASE_URI}/_execute/{algorithm_name}", | ||
body=input_json, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters