Skip to content

[ODSC-69670] AQUA version visibility changes #1215

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
49 changes: 47 additions & 2 deletions ads/aqua/extension/common_handler.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand All @@ -28,6 +32,46 @@ 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_aqua_version_path = os.path.join(
Copy link
Member

Choose a reason for hiding this comment

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

Let's make it a bit reliable, let's wrap the getting latest_version_artifact_path with the try catch block? Otherwise we don't want to break entire AQUA because of this validation :)

Copy link
Member

Choose a reason for hiding this comment

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

Apart from this LGTM!

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking of adding this try catch block at UI side so that we don't break entire AQUA but yeah this also sounds good. will update. Thanks

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated , thanks

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}}
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)


class CompatibilityCheckHandler(AquaAPIhandler):
"""The handler to check if the extension is compatible."""

Expand Down Expand Up @@ -118,4 +162,5 @@ def get(self):
("network_status", NetworkStatusHandler),
("hf_login", HFLoginHandler),
("hf_logged_in", HFUserStatusHandler),
("aqua_version", AquaVersionHandler),
]
3 changes: 3 additions & 0 deletions ads/aqua/version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"aqua": "1.0.7"
}
32 changes: 29 additions & 3 deletions tests/unitary/with_extras/aqua/test_common_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,25 @@
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..<OCID>"


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
self.common_handler = CompatibilityCheckHandler(MagicMock(), MagicMock())
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)
Expand All @@ -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"}}