99from typing import Dict , List , Optional
1010
1111from cachetools import TTLCache
12+ from oci .exceptions import ServiceError
13+ from oci .identity .models import Compartment
1214
1315from ads .aqua import logger
1416from ads .aqua .app import AquaApp
17+ from ads .aqua .common .entities import ContainerSpec
1518from ads .aqua .common .enums import Tags
1619from ads .aqua .common .errors import AquaResourceAccessError , AquaValueError
1720from ads .aqua .common .utils import get_container_config , load_config , sanitize_response
2730 TENANCY_OCID ,
2831)
2932from ads .telemetry import telemetry
30- from oci .exceptions import ServiceError
31- from oci .identity .models import Compartment
3233
3334
3435class ModelFormat (Enum ):
@@ -40,6 +41,19 @@ def to_dict(self):
4041 return self .value
4142
4243
44+ # todo: the container config spec information is shared across ui and deployment modules, move them
45+ # within ads.aqua.common.entities. In that case, check for circular imports due to usage of get_container_config.
46+
47+
48+ @dataclass (repr = False )
49+ class AquaContainerConfigSpec (DataClassSerializable ):
50+ cli_param : str = None
51+ server_port : str = None
52+ health_check_port : str = None
53+ env_vars : List [dict ] = None
54+ restricted_params : List [str ] = None
55+
56+
4357@dataclass (repr = False )
4458class AquaContainerConfigItem (DataClassSerializable ):
4559 """Represents an item of the AQUA container configuration."""
@@ -60,6 +74,7 @@ def __repr__(self):
6074 family : str = None
6175 platforms : List [Platform ] = None
6276 model_formats : List [ModelFormat ] = None
77+ spec : AquaContainerConfigSpec = field (default_factory = AquaContainerConfigSpec )
6378
6479
6580@dataclass (repr = False )
@@ -81,7 +96,9 @@ def to_dict(self):
8196
8297 @classmethod
8398 def from_container_index_json (
84- cls , config : Optional [Dict ] = None
99+ cls ,
100+ config : Optional [Dict ] = None ,
101+ enable_spec : Optional [bool ] = False ,
85102 ) -> "AquaContainerConfig" :
86103 """
87104 Create an AquaContainerConfig instance from a container index JSON.
@@ -90,6 +107,8 @@ def from_container_index_json(
90107 ----------
91108 config : Dict
92109 The container index JSON.
110+ enable_spec: bool
111+ flag to check if container specification details should be fetched.
93112
94113 Returns
95114 -------
@@ -114,6 +133,13 @@ def from_container_index_json(
114133 ModelFormat [model_format ]
115134 for model_format in container .get ("modelFormats" , [])
116135 ]
136+ container_spec = (
137+ config .get (ContainerSpec .CONTAINER_SPEC , {}).get (
138+ container_type , {}
139+ )
140+ if enable_spec
141+ else None
142+ )
117143 container_item = AquaContainerConfigItem (
118144 name = container .get ("name" , "" ),
119145 version = container .get ("version" , "" ),
@@ -123,6 +149,21 @@ def from_container_index_json(
123149 family = container_type ,
124150 platforms = platforms ,
125151 model_formats = model_formats ,
152+ spec = AquaContainerConfigSpec (
153+ cli_param = container_spec .get (ContainerSpec .CLI_PARM , "" ),
154+ server_port = container_spec .get (
155+ ContainerSpec .SERVER_PORT , ""
156+ ),
157+ health_check_port = container_spec .get (
158+ ContainerSpec .HEALTH_CHECK_PORT , ""
159+ ),
160+ env_vars = container_spec .get (ContainerSpec .ENV_VARS , []),
161+ restricted_params = container_spec .get (
162+ ContainerSpec .RESTRICTED_PARAMS , []
163+ ),
164+ )
165+ if container_spec
166+ else None ,
126167 )
127168 if container .get ("type" ) == "inference" :
128169 inference_items [container_type ] = container_item
@@ -571,5 +612,6 @@ def list_containers(self) -> AquaContainerConfig:
571612 The AQUA containers configurations.
572613 """
573614 return AquaContainerConfig .from_container_index_json (
574- config = get_container_config ()
615+ config = get_container_config (),
616+ enable_spec = True ,
575617 )
0 commit comments