File tree 6 files changed +48
-13
lines changed
6 files changed +48
-13
lines changed Original file line number Diff line number Diff line change 6
6
7
7
import logging
8
8
import sys
9
+ import os
10
+ from ads .aqua .utils import fetch_service_compartment
11
+
9
12
10
13
logger = logging .getLogger (__name__ )
11
14
handler = logging .StreamHandler (sys .stdout )
12
15
logger .setLevel (logging .INFO )
16
+
17
+
18
+ ODSC_MODEL_COMPARTMENT_OCID = os .environ .get ("ODSC_MODEL_COMPARTMENT_OCID" )
19
+ if not ODSC_MODEL_COMPARTMENT_OCID :
20
+ try :
21
+ ODSC_MODEL_COMPARTMENT_OCID = fetch_service_compartment ()
22
+ except :
23
+ logger .error (
24
+ "ODSC_MODEL_COMPARTMENT_OCID environment variable is not set for Aqua."
25
+ )
Original file line number Diff line number Diff line change 7
7
from importlib import metadata
8
8
9
9
from ads .aqua .extension .base_handler import AquaAPIhandler
10
+ from ads .aqua import ODSC_MODEL_COMPARTMENT_OCID
11
+ from ads .aqua .exception import AquaResourceAccessError
10
12
11
13
12
14
class ADSVersionHandler (AquaAPIhandler ):
@@ -16,6 +18,19 @@ def get(self):
16
18
self .finish ({"data" : metadata .version ("oracle_ads" )})
17
19
18
20
21
+ class CompatibilityCheckHandler (AquaAPIhandler ):
22
+ """The handler to check if the extension is compatible."""
23
+
24
+ def get (self ):
25
+ if ODSC_MODEL_COMPARTMENT_OCID :
26
+ return self .finish (dict (status = "ok" ))
27
+ else :
28
+ raise AquaResourceAccessError (
29
+ f"The AI Quick actions extension is not compatible in the given region."
30
+ )
31
+
32
+
19
33
__handlers__ = [
20
34
("ads_version" , ADSVersionHandler ),
35
+ ("hello" , CompatibilityCheckHandler ),
21
36
]
Original file line number Diff line number Diff line change 47
47
AQUA_SERVICE_MODELS_BUCKET ,
48
48
COMPARTMENT_OCID ,
49
49
CONDA_BUCKET_NS ,
50
- ODSC_MODEL_COMPARTMENT_OCID ,
51
50
PROJECT_OCID ,
52
51
TENANCY_OCID ,
53
52
)
53
+ from ads .aqua import ODSC_MODEL_COMPARTMENT_OCID
54
54
from ads .model import DataScienceModel
55
55
from ads .model .model_metadata import MetadataTaxonomyKeys , ModelCustomMetadata
56
56
from ads .telemetry import telemetry
Original file line number Diff line number Diff line change 29
29
from ads .common .oci_resource import SEARCH_TYPE , OCIResource
30
30
from ads .common .utils import get_console_link , upload_to_os
31
31
from ads .config import (
32
- AQUA_CONFIG_FOLDER ,
33
32
AQUA_SERVICE_MODELS_BUCKET ,
34
33
CONDA_BUCKET_NS ,
35
34
TENANCY_OCID ,
45
44
README = "README.md"
46
45
LICENSE_TXT = "config/LICENSE.txt"
47
46
DEPLOYMENT_CONFIG = "deployment_config.json"
47
+ COMPARTMENT_MAPPING_KEY = "service-model-compartment"
48
48
CONTAINER_INDEX = "container_index.json"
49
49
EVALUATION_REPORT_JSON = "report.json"
50
50
EVALUATION_REPORT_MD = "report.md"
@@ -574,6 +574,22 @@ def get_container_image(
574
574
return container_image
575
575
576
576
577
+ def fetch_service_compartment ():
578
+ """Loads the compartment mapping json from service bucket"""
579
+ config_file_name = (
580
+ f"oci://{ AQUA_SERVICE_MODELS_BUCKET } @{ CONDA_BUCKET_NS } /service_models/config"
581
+ )
582
+
583
+ config = load_config (
584
+ file_path = config_file_name ,
585
+ config_file_name = CONTAINER_INDEX ,
586
+ )
587
+ compartment_mapping = config .get (COMPARTMENT_MAPPING_KEY )
588
+ if compartment_mapping :
589
+ return compartment_mapping .get (CONDA_BUCKET_NS )
590
+ return None
591
+
592
+
577
593
def get_max_version (versions ):
578
594
"""Takes in a list of versions and returns the higher version."""
579
595
if not versions :
Original file line number Diff line number Diff line change 83
83
AQUA_SERVICE_NAME = "aqua"
84
84
DATA_SCIENCE_SERVICE_NAME = "data-science"
85
85
86
- compartment_mapping = {
87
- "idoaxnz5ar4s" : "ocid1.compartment.oc1..aaaaaaaabxqyb6w4kj5y4fwwkc47auxdothlqc7jpm3zbah5aamflvp7th3q" ,
88
- "id19sfcrra6z" : "ocid1.compartment.oc1..aaaaaaaasdur4tm5apdm6qyapaba7apdiyv22n2mwt6zquyubqevk3uo7nha" ,
89
- }
90
- default_compartment = compartment_mapping .get (CONDA_BUCKET_NS )
91
- ODSC_MODEL_COMPARTMENT_OCID = (
92
- default_compartment
93
- if default_compartment
94
- else os .environ .get ("ODSC_MODEL_COMPARTMENT_OCID" )
95
- )
96
-
97
86
98
87
def export (
99
88
uri : Optional [str ] = DEFAULT_CONFIG_PATH ,
Original file line number Diff line number Diff line change @@ -78,13 +78,15 @@ def setUpClass(cls):
78
78
os .environ ["CONDA_BUCKET_NS" ] = "test-namespace"
79
79
os .environ ["ODSC_MODEL_COMPARTMENT_OCID" ] = TestDataset .SERVICE_COMPARTMENT_ID
80
80
reload (ads .config )
81
+ reload (ads .aqua )
81
82
reload (ads .aqua .model )
82
83
83
84
@classmethod
84
85
def tearDownClass (cls ):
85
86
os .environ .pop ("CONDA_BUCKET_NS" , None )
86
87
os .environ .pop ("ODSC_MODEL_COMPARTMENT_OCID" , None )
87
88
reload (ads .config )
89
+ reload (ads .aqua )
88
90
reload (ads .aqua .model )
89
91
90
92
def test_list_service_models (self ):
You can’t perform that action at this time.
0 commit comments