From 659e6753f931ebe058625be3a29faade68e00469 Mon Sep 17 00:00:00 2001 From: Kumar Ranjan Date: Fri, 27 Jun 2025 03:00:46 +0530 Subject: [PATCH 1/6] Adding version handler for aqua --- ads/aqua/client/client.py | 6 ++-- ads/aqua/extension/common_handler.py | 45 ++++++++++++++++++++++++++-- ads/aqua/version.json | 6 ++++ 3 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 ads/aqua/version.json diff --git a/ads/aqua/client/client.py b/ads/aqua/client/client.py index b2a0490a7..1298a9a63 100644 --- a/ads/aqua/client/client.py +++ b/ads/aqua/client/client.py @@ -314,11 +314,9 @@ def _parse_streaming_line( try: json_line = json.loads(line) logger.debug(f"Parsed JSON line: {json_line}") - except json.JSONDecodeError as e: + except json.JSONDecodeError: logger.debug(f"Error decoding JSON from line: {line}") - raise json.JSONDecodeError( - f"Error decoding JSON from line: {e!s}", e.doc, e.pos - ) from e + return None if json_line.get("object") == "error": # Raise an error for error objects in the stream diff --git a/ads/aqua/extension/common_handler.py b/ads/aqua/extension/common_handler.py index 002c7c860..b5ffd4336 100644 --- a/ads/aqua/extension/common_handler.py +++ b/ads/aqua/extension/common_handler.py @@ -1,8 +1,8 @@ #!/usr/bin/env python # Copyright (c) 2025 Oracle and/or its affiliates. # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ - - +import json +import os from importlib import metadata import huggingface_hub @@ -18,6 +18,10 @@ ) from ads.aqua.extension.base_handler import AquaAPIhandler from ads.aqua.extension.errors import Errors +from ads.common.object_storage_details import ObjectStorageDetails +from ads.common.utils import read_file +from ads.config import CONDA_BUCKET_NAME, CONDA_BUCKET_NS +from ads.opctl.operator.common.utils import default_signer class ADSVersionHandler(AquaAPIhandler): @@ -28,6 +32,42 @@ def get(self): self.finish({"data": metadata.version("oracle_ads")}) +class AquaVersionHandler(AquaAPIhandler): + @handle_exceptions + def get(self): + """ + Returns the current and latest deployed version of AQUA + + { + "installed": { + "aqua": "0.1.3.0", + "ads": "2.14.2" + }, + "latest": { + "aqua": "0.1.4.0", + "ads": "2.14.4" + } + } + + """ + + current_version_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), "..", "version.json" + ) + latest_version_artifact_path = ObjectStorageDetails( + CONDA_BUCKET_NAME, CONDA_BUCKET_NS, "service_pack/aqua_latest_version.json" + ).path + latest_version_content = read_file( + latest_version_artifact_path, auth=default_signer() + ) + current_version_content = read_file(current_version_path) + response = { + **json.loads(current_version_content), + **json.loads(latest_version_content), + } + return self.finish(response) + + class CompatibilityCheckHandler(AquaAPIhandler): """The handler to check if the extension is compatible.""" @@ -118,4 +158,5 @@ def get(self): ("network_status", NetworkStatusHandler), ("hf_login", HFLoginHandler), ("hf_logged_in", HFUserStatusHandler), + ("aqua_version", AquaVersionHandler), ] diff --git a/ads/aqua/version.json b/ads/aqua/version.json new file mode 100644 index 000000000..e3159b23c --- /dev/null +++ b/ads/aqua/version.json @@ -0,0 +1,6 @@ +{ + "installed": { + "ads": "2.14.2", + "aqua": "0.1.3.0" + } +} From ddb32469a92aa310c93d23fca5b0e71283b533f1 Mon Sep 17 00:00:00 2001 From: Kumar Ranjan Date: Fri, 27 Jun 2025 03:05:48 +0530 Subject: [PATCH 2/6] Reverting AQUA client changes --- ads/aqua/client/client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ads/aqua/client/client.py b/ads/aqua/client/client.py index 1298a9a63..b2a0490a7 100644 --- a/ads/aqua/client/client.py +++ b/ads/aqua/client/client.py @@ -314,9 +314,11 @@ def _parse_streaming_line( try: json_line = json.loads(line) logger.debug(f"Parsed JSON line: {json_line}") - except json.JSONDecodeError: + except json.JSONDecodeError as e: logger.debug(f"Error decoding JSON from line: {line}") - return None + raise json.JSONDecodeError( + f"Error decoding JSON from line: {e!s}", e.doc, e.pos + ) from e if json_line.get("object") == "error": # Raise an error for error objects in the stream From f8fde33daff1185bd23131c0263934e528a8c4b1 Mon Sep 17 00:00:00 2001 From: Kumar Ranjan Date: Mon, 30 Jun 2025 20:50:30 +0530 Subject: [PATCH 3/6] Addressing review comments --- ads/aqua/extension/common_handler.py | 18 ++++++++++-------- ads/aqua/modeldeployment/entities.py | 2 ++ ads/aqua/version.json | 5 +---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ads/aqua/extension/common_handler.py b/ads/aqua/extension/common_handler.py index b5ffd4336..780ea032f 100644 --- a/ads/aqua/extension/common_handler.py +++ b/ads/aqua/extension/common_handler.py @@ -51,20 +51,22 @@ def get(self): """ - current_version_path = os.path.join( + current_aqua_version_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), "..", "version.json" ) + current_aqua_version = json.loads(read_file(current_aqua_version_path)) + current_ads_version = {"ads": metadata.version("oracle_ads")} + current_version = {"installed": {**current_aqua_version, **current_ads_version}} + latest_version_artifact_path = ObjectStorageDetails( CONDA_BUCKET_NAME, CONDA_BUCKET_NS, "service_pack/aqua_latest_version.json" ).path - latest_version_content = read_file( - latest_version_artifact_path, auth=default_signer() + + latest_version = json.loads( + read_file(latest_version_artifact_path, auth=default_signer()) ) - current_version_content = read_file(current_version_path) - response = { - **json.loads(current_version_content), - **json.loads(latest_version_content), - } + + response = {**current_version, **latest_version} return self.finish(response) diff --git a/ads/aqua/modeldeployment/entities.py b/ads/aqua/modeldeployment/entities.py index ebce26dc8..c84762a65 100644 --- a/ads/aqua/modeldeployment/entities.py +++ b/ads/aqua/modeldeployment/entities.py @@ -147,6 +147,8 @@ def from_oci_model_deployment( AquaDeployment: The instance of the Aqua model deployment. """ + print("oci_model_deployment: ", oci_model_deployment) + instance_configuration = oci_model_deployment.model_deployment_configuration_details.model_configuration_details.instance_configuration instance_shape_config_details = ( instance_configuration.model_deployment_instance_shape_config_details diff --git a/ads/aqua/version.json b/ads/aqua/version.json index e3159b23c..5e39675c5 100644 --- a/ads/aqua/version.json +++ b/ads/aqua/version.json @@ -1,6 +1,3 @@ { - "installed": { - "ads": "2.14.2", - "aqua": "0.1.3.0" - } + "aqua": "1.0.7" } From a0e8a28e456d74cb2685b2b624637f47fb61e79a Mon Sep 17 00:00:00 2001 From: Kumar Ranjan Date: Mon, 30 Jun 2025 21:13:23 +0530 Subject: [PATCH 4/6] Adding UTs --- .../with_extras/aqua/test_common_handler.py | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/tests/unitary/with_extras/aqua/test_common_handler.py b/tests/unitary/with_extras/aqua/test_common_handler.py index f253b76d3..7a0c282ef 100644 --- a/tests/unitary/with_extras/aqua/test_common_handler.py +++ b/tests/unitary/with_extras/aqua/test_common_handler.py @@ -14,14 +14,17 @@ import ads.aqua import ads.config -from ads.aqua.extension.common_handler import CompatibilityCheckHandler +from ads.aqua.extension.common_handler import ( + CompatibilityCheckHandler, + AquaVersionHandler, +) class TestDataset: SERVICE_COMPARTMENT_ID = "ocid1.compartment.oc1.." -class TestEvaluationHandler(unittest.TestCase): +class TestCompatibilityCheckHandler(unittest.TestCase): @patch.object(IPythonHandler, "__init__") def setUp(self, ipython_init_mock) -> None: ipython_init_mock.return_value = None @@ -29,7 +32,7 @@ def setUp(self, ipython_init_mock) -> None: self.common_handler.request = MagicMock() def test_get_ok(self): - """Test to check if ok is returned when ODSC_MODEL_COMPARTMENT_OCID is set.""" + """Test to check if ok is returned.""" reload(ads.config) reload(ads.aqua) reload(ads.aqua.extension.utils) @@ -42,3 +45,26 @@ def test_get_ok(self): self.common_handler.request.path = "aqua/hello" result = self.common_handler.get() assert result["status"] == "ok" + + +class TestAquaVersionHandler(unittest.TestCase): + @patch.object(IPythonHandler, "__init__") + def setUp(self, ipython_init_mock) -> None: + ipython_init_mock.return_value = None + self.version_handler = AquaVersionHandler(MagicMock(), MagicMock()) + self.version_handler.request = MagicMock() + + @patch("ads.common.utils.read_file") + def test_get(self, mock_read_file): + reload(ads.config) + reload(ads.aqua) + reload(ads.aqua.extension.utils) + reload(ads.aqua.extension.common_handler) + mock_read_file.return_value = '{"installed":{"aqua":"1.0.4","ads":"2.13.12"}}' + with patch( + "ads.aqua.extension.base_handler.AquaAPIhandler.finish" + ) as mock_finish: + mock_finish.side_effect = lambda x: x + self.version_handler.request.path = "aqua/aqua_version" + result = self.version_handler.get() + assert result == {"installed": {"aqua": "1.0.4", "ads": "2.13.12"}} From d19d9f3367352ca526648219dc5acbb456070358 Mon Sep 17 00:00:00 2001 From: Kumar Ranjan Date: Mon, 30 Jun 2025 21:15:26 +0530 Subject: [PATCH 5/6] Reverting print statement --- ads/aqua/modeldeployment/entities.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ads/aqua/modeldeployment/entities.py b/ads/aqua/modeldeployment/entities.py index c84762a65..ebce26dc8 100644 --- a/ads/aqua/modeldeployment/entities.py +++ b/ads/aqua/modeldeployment/entities.py @@ -147,8 +147,6 @@ def from_oci_model_deployment( AquaDeployment: The instance of the Aqua model deployment. """ - print("oci_model_deployment: ", oci_model_deployment) - instance_configuration = oci_model_deployment.model_deployment_configuration_details.model_configuration_details.instance_configuration instance_shape_config_details = ( instance_configuration.model_deployment_instance_shape_config_details From 5d7605ba8f0e4dfaeaa5390d25c8464951b89354 Mon Sep 17 00:00:00 2001 From: Kumar Ranjan Date: Wed, 2 Jul 2025 02:24:25 +0530 Subject: [PATCH 6/6] Addressing review comments --- ads/aqua/extension/common_handler.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/ads/aqua/extension/common_handler.py b/ads/aqua/extension/common_handler.py index 780ea032f..40c6e7b0c 100644 --- a/ads/aqua/extension/common_handler.py +++ b/ads/aqua/extension/common_handler.py @@ -57,15 +57,17 @@ def get(self): current_aqua_version = json.loads(read_file(current_aqua_version_path)) current_ads_version = {"ads": metadata.version("oracle_ads")} current_version = {"installed": {**current_aqua_version, **current_ads_version}} - - latest_version_artifact_path = ObjectStorageDetails( - CONDA_BUCKET_NAME, CONDA_BUCKET_NS, "service_pack/aqua_latest_version.json" - ).path - - latest_version = json.loads( - read_file(latest_version_artifact_path, auth=default_signer()) - ) - + try: + latest_version_artifact_path = ObjectStorageDetails( + CONDA_BUCKET_NAME, + CONDA_BUCKET_NS, + "service_pack/aqua_latest_version.json", + ).path + latest_version = json.loads( + read_file(latest_version_artifact_path, auth=default_signer()) + ) + except Exception: + latest_version = {"latest": current_version["installed"]} response = {**current_version, **latest_version} return self.finish(response)