Skip to content
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

Added delete task API. #127

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions opensearch_py_ml/ml_commons/ml_commons_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,20 @@ def delete_model(self, model_id: str) -> object:
method="DELETE",
url=API_URL,
)

def delete_task(self, task_id: str) -> object:
"""
This method deletes a task from opensearch cluster (using ml commons api)

:param task_id: unique id of the task
:type task_id: string
:return: returns a json object, with detailed information about the deleted task
:rtype: object
"""

API_URL = f"{ML_BASE_URI}/tasks/{task_id}"

return self._client.transport.perform_request(
method="DELETE",
url=API_URL,
)
7 changes: 7 additions & 0 deletions tests/ml_commons/test_ml_commons_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ def test_integration_model_train_upload_full_cycle():
raised == False
), "Raised Exception in generating sentence embedding"

try:
delete_task_obj = ml_client.delete_task(task_id)
assert delete_task_obj.get("result") == "deleted"
except: # noqa: E722
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should specify the exception here to avoid a too broad except

raised = True
assert raised == False, "Raised Exception in deleting task"

try:
ml_client.unload_model(model_id)
for i in range(int(UNLOAD_TIMEOUT / 10)):
Expand Down