Skip to content

Commit f04f450

Browse files
authored
Merge branch 'main' into operators_docs_update
2 parents a07aeaf + 65819e4 commit f04f450

File tree

20 files changed

+132
-306
lines changed

20 files changed

+132
-306
lines changed

ads/aqua/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
get_async_httpx_client,
1515
get_httpx_client,
1616
)
17-
from ads.aqua.common.utils import fetch_service_compartment
1817
from ads.config import OCI_RESOURCE_PRINCIPAL_VERSION
1918

2019
ENV_VAR_LOG_LEVEL = "ADS_AQUA_LOG_LEVEL"
@@ -39,7 +38,3 @@ def set_log_level(log_level: str):
3938

4039
if OCI_RESOURCE_PRINCIPAL_VERSION:
4140
set_auth("resource_principal")
42-
43-
ODSC_MODEL_COMPARTMENT_OCID = (
44-
os.environ.get("ODSC_MODEL_COMPARTMENT_OCID") or fetch_service_compartment()
45-
)

ads/aqua/cli.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*--
32

4-
# Copyright (c) 2024 Oracle and/or its affiliates.
3+
# Copyright (c) 2024, 2025 Oracle and/or its affiliates.
54
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
65
import os
76

87
from ads.aqua import (
98
ENV_VAR_LOG_LEVEL,
10-
ODSC_MODEL_COMPARTMENT_OCID,
119
logger,
1210
set_log_level,
1311
)
14-
from ads.aqua.common.errors import AquaCLIError, AquaConfigError
12+
from ads.aqua.common.errors import AquaCLIError
1513
from ads.aqua.evaluation import AquaEvaluationApp
1614
from ads.aqua.finetuning import AquaFineTuningApp
1715
from ads.aqua.model import AquaModelApp
1816
from ads.aqua.modeldeployment import AquaDeploymentApp
1917
from ads.common.utils import LOG_LEVELS
20-
from ads.config import NB_SESSION_OCID
2118

2219

2320
class AquaCommand:
@@ -82,16 +79,6 @@ def __init__(
8279

8380
set_log_level(aqua_log_level)
8481

85-
if not ODSC_MODEL_COMPARTMENT_OCID:
86-
if NB_SESSION_OCID:
87-
raise AquaConfigError(
88-
f"Aqua is not available for the notebook session {NB_SESSION_OCID}. For more information, "
89-
f"please refer to the documentation."
90-
)
91-
raise AquaConfigError(
92-
"ODSC_MODEL_COMPARTMENT_OCID environment variable is not set for Aqua."
93-
)
94-
9582
@staticmethod
9683
def _validate_value(flag, value):
9784
"""Check if the given value for bool flag is valid.

ads/aqua/common/utils.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@
5050
)
5151
from ads.aqua.constants import (
5252
AQUA_GA_LIST,
53-
COMPARTMENT_MAPPING_KEY,
5453
CONSOLE_LINK_RESOURCE_TYPE_MAPPING,
55-
CONTAINER_INDEX,
5654
DEPLOYMENT_CONFIG,
5755
FINE_TUNING_CONFIG,
5856
HF_LOGIN_DEFAULT_TIMEOUT,
@@ -561,36 +559,6 @@ def _build_job_identifier(
561559
return AquaResourceIdentifier()
562560

563561

564-
def service_config_path():
565-
return f"oci://{AQUA_SERVICE_MODELS_BUCKET}@{CONDA_BUCKET_NS}/service_models/config"
566-
567-
568-
def fetch_service_compartment() -> Union[str, None]:
569-
"""
570-
Loads the compartment mapping json from service bucket.
571-
This json file has a service-model-compartment key which contains a dictionary of namespaces
572-
and the compartment OCID of the service models in that namespace.
573-
"""
574-
config_file_name = (
575-
f"oci://{AQUA_SERVICE_MODELS_BUCKET}@{CONDA_BUCKET_NS}/service_models/config"
576-
)
577-
578-
try:
579-
config = load_config(
580-
file_path=config_file_name,
581-
config_file_name=CONTAINER_INDEX,
582-
)
583-
except Exception as e:
584-
logger.debug(
585-
f"Config file {config_file_name}/{CONTAINER_INDEX} to fetch service compartment OCID "
586-
f"could not be found. \n{str(e)}."
587-
)
588-
return
589-
compartment_mapping = config.get(COMPARTMENT_MAPPING_KEY)
590-
if compartment_mapping:
591-
return compartment_mapping.get(CONDA_BUCKET_NS)
592-
593-
594562
def get_max_version(versions):
595563
"""Takes in a list of versions and returns the higher version."""
596564
if not versions:

ads/aqua/config/container_config.py

Lines changed: 13 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from oci.data_science.models import ContainerSummary
88
from pydantic import Field
99

10-
from ads.aqua.common.entities import ContainerSpec
1110
from ads.aqua.config.utils.serializer import Serializable
1211
from ads.aqua.constants import (
1312
SERVICE_MANAGED_CONTAINER_URI_SCHEME,
@@ -185,24 +184,32 @@ def from_service_config(
185184
0
186185
].additional_configurations.get(
187186
"MODEL_DEPLOY_PREDICT_ENDPOINT", UNKNOWN
188-
),
187+
)
188+
},
189+
{
189190
"MODEL_DEPLOY_HEALTH_ENDPOINT": container.workload_configuration_details_list[
190191
0
191192
].additional_configurations.get(
192193
"MODEL_DEPLOY_HEALTH_ENDPOINT", UNKNOWN
193-
),
194+
)
195+
},
196+
{
194197
"MODEL_DEPLOY_ENABLE_STREAMING": container.workload_configuration_details_list[
195198
0
196199
].additional_configurations.get(
197200
"MODEL_DEPLOY_ENABLE_STREAMING", UNKNOWN
198-
),
201+
)
202+
},
203+
{
199204
"PORT": container.workload_configuration_details_list[
200205
0
201-
].additional_configurations.get("PORT", ""),
206+
].additional_configurations.get("PORT", "")
207+
},
208+
{
202209
"HEALTH_CHECK_PORT": container.workload_configuration_details_list[
203210
0
204211
].additional_configurations.get("HEALTH_CHECK_PORT", UNKNOWN),
205-
}
212+
},
206213
]
207214
container_spec = AquaContainerConfigSpec(
208215
cli_param=container.workload_configuration_details_list[0].cmd,
@@ -239,88 +246,3 @@ def from_service_config(
239246
return cls(
240247
inference=inference_items, finetune=finetune_items, evaluate=evaluate_items
241248
)
242-
243-
@classmethod
244-
def from_container_index_json(
245-
cls,
246-
config: Dict,
247-
enable_spec: Optional[bool] = False,
248-
) -> "AquaContainerConfig":
249-
"""
250-
Creates an AquaContainerConfig instance from a container index JSON.
251-
252-
Parameters
253-
----------
254-
config (Optional[Dict]): The container index JSON.
255-
enable_spec (Optional[bool]): If True, fetch container specification details.
256-
257-
Returns
258-
-------
259-
AquaContainerConfig: The constructed container configuration.
260-
"""
261-
# TODO: Return this logic back if necessary in the next iteraion.
262-
# if not config:
263-
# config = get_container_config()
264-
inference_items: Dict[str, AquaContainerConfigItem] = {}
265-
finetune_items: Dict[str, AquaContainerConfigItem] = {}
266-
evaluate_items: Dict[str, AquaContainerConfigItem] = {}
267-
268-
for container_type, containers in config.items():
269-
if isinstance(containers, list):
270-
for container in containers:
271-
platforms = container.get("platforms", [])
272-
model_formats = container.get("modelFormats", [])
273-
usages = container.get("usages", [])
274-
container_spec = (
275-
config.get(ContainerSpec.CONTAINER_SPEC, {}).get(
276-
container_type, {}
277-
)
278-
if enable_spec
279-
else None
280-
)
281-
container_item = AquaContainerConfigItem(
282-
name=container.get("name", ""),
283-
version=container.get("version", ""),
284-
display_name=container.get(
285-
"displayName", container.get("version", "")
286-
),
287-
family=container_type,
288-
platforms=platforms,
289-
model_formats=model_formats,
290-
usages=usages,
291-
spec=(
292-
AquaContainerConfigSpec(
293-
cli_param=container_spec.get(
294-
ContainerSpec.CLI_PARM, ""
295-
),
296-
server_port=container_spec.get(
297-
ContainerSpec.SERVER_PORT, ""
298-
),
299-
health_check_port=container_spec.get(
300-
ContainerSpec.HEALTH_CHECK_PORT, ""
301-
),
302-
env_vars=container_spec.get(ContainerSpec.ENV_VARS, []),
303-
restricted_params=container_spec.get(
304-
ContainerSpec.RESTRICTED_PARAMS, []
305-
),
306-
)
307-
if container_spec
308-
else None
309-
),
310-
)
311-
if container.get("type").lower() == "inference":
312-
inference_items[container_type] = container_item
313-
elif (
314-
container.get("type").lower() == "fine-tune"
315-
or container_type == "odsc-llm-fine-tuning"
316-
):
317-
finetune_items[container_type] = container_item
318-
elif (
319-
container.get("type").lower() in ("evaluation", "evaluate")
320-
or container_type == "odsc-llm-evaluate"
321-
):
322-
evaluate_items[container_type] = container_item
323-
324-
return cls(
325-
inference=inference_items, finetune=finetune_items, evaluate=evaluate_items
326-
)
Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
#!/usr/bin/env python
22

3-
# Copyright (c) 2024 Oracle and/or its affiliates.
3+
# Copyright (c) 2024, 2025 Oracle and/or its affiliates.
44
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
55

66
import json
77
from importlib import metadata
8-
from typing import List, Union
8+
from typing import List, Optional, Union
99

1010
from ads.aqua.common.decorator import handle_exceptions
11-
from ads.aqua.common.errors import AquaResourceAccessError
12-
from ads.aqua.common.utils import known_realm
1311
from ads.aqua.extension.aqua_ws_msg_handler import AquaWSMsgHandler
1412
from ads.aqua.extension.models.ws_models import (
1513
AdsVersionResponse,
16-
CompatibilityCheckResponse,
1714
RequestResponseType,
1815
)
19-
from ads.aqua.extension.utils import ui_compatability_check
2016

2117

2218
class AquaCommonWsMsgHandler(AquaWSMsgHandler):
@@ -28,7 +24,7 @@ def __init__(self, message: Union[str, bytes]):
2824
super().__init__(message)
2925

3026
@handle_exceptions
31-
def process(self) -> Union[AdsVersionResponse, CompatibilityCheckResponse]:
27+
def process(self) -> Optional[AdsVersionResponse]:
3228
request = json.loads(self.message)
3329
if request.get("kind") == "AdsVersion":
3430
version = metadata.version("oracle_ads")
@@ -38,20 +34,3 @@ def process(self) -> Union[AdsVersionResponse, CompatibilityCheckResponse]:
3834
data=version,
3935
)
4036
return response
41-
if request.get("kind") == "CompatibilityCheck":
42-
if ui_compatability_check():
43-
return CompatibilityCheckResponse(
44-
message_id=request.get("message_id"),
45-
kind=RequestResponseType.CompatibilityCheck,
46-
data={"status": "ok"},
47-
)
48-
elif known_realm():
49-
return CompatibilityCheckResponse(
50-
message_id=request.get("message_id"),
51-
kind=RequestResponseType.CompatibilityCheck,
52-
data={"status": "compatible"},
53-
)
54-
else:
55-
raise AquaResourceAccessError(
56-
"The AI Quick actions extension is not compatible in the given region."
57-
)

ads/aqua/extension/model_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from ads.aqua.extension.errors import Errors
1616
from ads.aqua.model import AquaModelApp
1717
from ads.aqua.model.entities import AquaModelSummary, HFModelSummary
18-
from ads.config import USER
18+
from ads.config import SERVICE
1919
from ads.model.common.utils import MetadataArtifactPathType
2020

2121

@@ -82,7 +82,7 @@ def list(self):
8282
# project_id is no needed.
8383
project_id = self.get_argument("project_id", default=None)
8484
model_type = self.get_argument("model_type", default=None)
85-
category = self.get_argument("category", default=USER)
85+
category = self.get_argument("category", default=SERVICE)
8686
return self.finish(
8787
AquaModelApp().list(
8888
compartment_id=compartment_id,

ads/aqua/extension/utils.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
#!/usr/bin/env python
2-
# Copyright (c) 2024 Oracle and/or its affiliates.
2+
# Copyright (c) 2024, 2025 Oracle and/or its affiliates.
33
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
44

55
import re
66
import traceback
77
import uuid
88
from dataclasses import fields
9-
from datetime import datetime, timedelta
109
from http.client import responses
1110
from typing import Dict, Optional
1211

13-
from cachetools import TTLCache, cached
1412
from tornado.web import HTTPError
1513

16-
from ads.aqua import ODSC_MODEL_COMPARTMENT_OCID, logger
17-
from ads.aqua.common.utils import fetch_service_compartment
14+
from ads.aqua import logger
1815
from ads.aqua.constants import (
1916
AQUA_TROUBLESHOOTING_LINK,
2017
OCI_OPERATION_FAILURES,
@@ -36,19 +33,11 @@ def validate_function_parameters(data_class, input_data: Dict):
3633
)
3734

3835

39-
@cached(cache=TTLCache(maxsize=1, ttl=timedelta(minutes=1), timer=datetime.now))
40-
def ui_compatability_check():
41-
"""This method caches the service compartment OCID details that is set by either the environment variable or if
42-
fetched from the configuration. The cached result is returned when multiple calls are made in quick succession
43-
from the UI to avoid multiple config file loads."""
44-
return ODSC_MODEL_COMPARTMENT_OCID or fetch_service_compartment()
45-
46-
4736
def get_default_error_messages(
4837
service_payload: dict,
4938
status_code: str,
5039
default_msg: str = "Unknown HTTP Error.",
51-
)-> str:
40+
) -> str:
5241
"""Method that maps the error messages based on the operation performed or the status codes encountered."""
5342

5443
if service_payload and "operation_name" in service_payload:
@@ -66,14 +55,13 @@ def get_documentation_link(key: str) -> str:
6655
return f"{AQUA_TROUBLESHOOTING_LINK}#{github_header}"
6756

6857

69-
def get_troubleshooting_tips(service_payload: dict,
70-
status_code: str) -> str:
58+
def get_troubleshooting_tips(service_payload: dict, status_code: str) -> str:
7159
"""Maps authorization errors to potential solutions on Troubleshooting Page per Aqua Documentation on oci-data-science-ai-samples"""
7260

7361
tip = f"For general tips on troubleshooting: {AQUA_TROUBLESHOOTING_LINK}"
7462

7563
if status_code in (404, 400):
76-
failed_operation = service_payload.get('operation_name')
64+
failed_operation = service_payload.get("operation_name")
7765

7866
if failed_operation in OCI_OPERATION_FAILURES:
7967
link = get_documentation_link(failed_operation)
@@ -118,14 +106,13 @@ def construct_error(status_code: int, **kwargs) -> ReplyDetails:
118106

119107
tips = get_troubleshooting_tips(service_payload, status_code)
120108

121-
122109
reply = ReplyDetails(
123-
status = status_code,
124-
troubleshooting_tips = tips,
125-
message = message,
126-
service_payload = service_payload,
127-
reason = reason,
128-
request_id = str(uuid.uuid4()),
110+
status=status_code,
111+
troubleshooting_tips=tips,
112+
message=message,
113+
service_payload=service_payload,
114+
reason=reason,
115+
request_id=str(uuid.uuid4()),
129116
)
130117

131118
exc_info = kwargs.get("exc_info")

0 commit comments

Comments
 (0)