-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search task added #177
Search task added #177
Changes from 1 commit
4c8fbf9
d995566
454499d
fa5ccbb
33be035
867e708
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -405,6 +405,34 @@ def search_task(self, input_json) -> object: | |
body=API_BODY, | ||
) | ||
|
||
def search_model(self, input_json) -> object: | ||
""" | ||
This method searches a task from opensearch cluster (using ml commons api) | ||
:param json: json input for the search request | ||
:type json: string or dict | ||
:return: returns a json object, with detailed information about the searched task | ||
:rtype: object | ||
""" | ||
|
||
API_URL = f"{ML_BASE_URI}/models/_search" | ||
|
||
if isinstance(input_json, str): | ||
try: | ||
json_obj = json.loads(input_json) | ||
API_BODY = json.dumps(json_obj) | ||
except json.JSONDecodeError: | ||
return "Invalid JSON string passed as argument." | ||
elif isinstance(input_json, dict): | ||
API_BODY = json.dumps(input_json) | ||
else: | ||
return "Invalid JSON object passed as argument." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we cover this line with testing? May be we can write separate test function just to cover this line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean "else" block? I covered both dict and string test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "return "Invalid JSON object passed as argument." this block There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see maybe you mean try catch block missed for dict case. I will add it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ok |
||
|
||
return self._client.transport.perform_request( | ||
method="POST", | ||
url=API_URL, | ||
body=API_BODY, | ||
) | ||
|
||
|
||
def get_model_info(self, model_id: str) -> object: | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,18 +100,19 @@ def test_execute(): | |
), "Raised Exception during execute API testing with JSON string" | ||
|
||
def test_search(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will it be better if we print out error message? |
||
#Search task cases | ||
raised = False | ||
try: | ||
search_task_obj = ml_client.search_task(input_json='{"query": {"match_all": {}},"size": 1}') | ||
assert search_task_obj["_shards"]["successful"] == 1 | ||
assert search_task_obj["hits"]["hits"] != [] | ||
except: # noqa: E722 | ||
raised = True | ||
assert raised == False, "Raised Exception in searching task" | ||
|
||
raised = False | ||
try: | ||
search_task_obj = ml_client.search_task(input_json={"query": {"match_all": {}},"size": 1}) | ||
assert search_task_obj["_shards"]["successful"] == 1 | ||
assert search_task_obj["hits"]["hits"] != [] | ||
except: # noqa: E722 | ||
raised = True | ||
assert raised == False, "Raised Exception in searching task" | ||
|
@@ -124,6 +125,31 @@ def test_search(): | |
raised = True | ||
assert raised == False, "Raised Exception in searching task" | ||
|
||
#Search model cases | ||
raised = False | ||
try: | ||
search_model_obj = ml_client.search_model(input_json='{"query": {"match_all": {}},"size": 1}') | ||
assert search_model_obj["hits"]["hits"] != [] | ||
except: # noqa: E722 | ||
raised = True | ||
assert raised == False, "Raised Exception in searching model" | ||
|
||
raised = False | ||
try: | ||
search_model_obj = ml_client.search_model(input_json={"query": {"match_all": {}},"size": 1}) | ||
assert search_model_obj["hits"]["hits"] != [] | ||
except: # noqa: E722 | ||
raised = True | ||
assert raised == False, "Raised Exception in searching model" | ||
|
||
raised = False | ||
try: | ||
search_model_obj = ml_client.search_model(input_json=15) | ||
assert search_model_obj == "Invalid JSON object passed as argument." | ||
except: # noqa: E722 | ||
raised = True | ||
assert raised == False, "Raised Exception in searching model" | ||
|
||
|
||
def test_DEPRECATED_integration_pretrained_model_upload_unload_delete(): | ||
raised = False | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we cover this section also? We can easily cover by sending
ml_client.search_model(input_json='15')