Skip to content

Commit 55b6f18

Browse files
authored
fix: refactor validators in ml_commons client (#385)
* fix Signed-off-by: kalyanr <[email protected]> * update changelog Signed-off-by: kalyanr <[email protected]> --------- Signed-off-by: kalyanr <[email protected]>
1 parent 529ee34 commit 55b6f18

File tree

8 files changed

+13
-26
lines changed

8 files changed

+13
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
3838
- use try-except-else block for handling unexpected exceptions during integration tests by @rawwar([#370](https://github.com/opensearch-project/opensearch-py-ml/pull/370))
3939
- Removed pandas version pin in nox tests by @rawwar ([#368](https://github.com/opensearch-project/opensearch-py-ml/pull/368))
4040
- Switch AL2 to AL2023 agent and DockerHub to ECR images in ml-models.JenkinsFile ([#377](https://github.com/opensearch-project/opensearch-py-ml/pull/377))
41+
- Refactored validators in ML Commons' client([#385](https://github.com/opensearch-project/opensearch-py-ml/pull/385))
4142

4243
### Fixed
4344
- Enable make_model_config_json to add model description to model config file by @thanawan-atc in ([#203](https://github.com/opensearch-project/opensearch-py-ml/pull/203))

opensearch_py_ml/ml_commons/ml_commons_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from opensearch_py_ml.ml_commons.model_connector import Connector
2626
from opensearch_py_ml.ml_commons.model_execute import ModelExecute
2727
from opensearch_py_ml.ml_commons.model_uploader import ModelUploader
28-
from opensearch_py_ml.ml_commons.validators.profile import validate_profile_input
28+
from opensearch_py_ml.ml_commons.validators import validate_profile_input
2929

3030

3131
class MLCommonClient:

opensearch_py_ml/ml_commons/model_access_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from opensearchpy.exceptions import NotFoundError
1212

1313
from opensearch_py_ml.ml_commons.ml_common_utils import ML_BASE_URI
14-
from opensearch_py_ml.ml_commons.validators.model_access_control import (
14+
from opensearch_py_ml.ml_commons.validators import (
1515
validate_create_model_group_parameters,
1616
validate_delete_model_group_parameters,
1717
validate_search_model_group_parameters,

opensearch_py_ml/ml_commons/validators/model_access_control.py renamed to opensearch_py_ml/ml_commons/validators.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,11 @@ def validate_delete_model_group_parameters(model_group_id: str):
9595

9696
def validate_search_model_group_parameters(query: dict):
9797
_validate_model_group_query(query)
98+
99+
100+
def validate_profile_input(path_parameter, payload):
101+
if path_parameter is not None and not isinstance(path_parameter, str):
102+
raise ValueError("path_parameter needs to be a string or None")
103+
104+
if payload is not None and not isinstance(payload, dict):
105+
raise ValueError("payload needs to be a dictionary or None")

opensearch_py_ml/ml_commons/validators/__init__.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

opensearch_py_ml/ml_commons/validators/profile.py

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import pytest
99

10-
from opensearch_py_ml.ml_commons.validators.model_access_control import (
10+
from opensearch_py_ml.ml_commons.validators import (
1111
_validate_model_group_access_mode,
1212
_validate_model_group_add_all_backend_roles,
1313
_validate_model_group_backend_roles,

tests/ml_models/test_sentencetransformermodel_pytest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def test_overwrite_description():
463463
def test_long_description():
464464
model_id = "sentence-transformers/gtr-t5-base"
465465
model_format = "TORCH_SCRIPT"
466-
expected_model_description = "This is a sentence-transformers model: It maps sentences & paragraphs to a 768 dimensional dense vector space. The model was specifically trained for the task of sematic search."
466+
expected_model_description = "This is a sentence-transformers model: It maps sentences & paragraphs to a 768 dimensional dense vector space. The model was specifically trained for the task of semantic search."
467467

468468
clean_test_folder(TEST_FOLDER)
469469
test_model12 = SentenceTransformerModel(

0 commit comments

Comments
 (0)