Skip to content

Commit cdcf5c8

Browse files
committed
Auto Select Latest Conda Pack
1 parent 3a13534 commit cdcf5c8

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

ads/opctl/operator/cmd.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
import fsspec
1919
import yaml
2020
from ads.opctl.operator.common.utils import print_traceback
21+
import ads
22+
from ads.common import oci_client as oc
23+
from ads.config import (
24+
CONDA_BUCKET_NAME,
25+
CONDA_BUCKET_NS,
26+
)
2127
from tabulate import tabulate
2228

2329
from ads.common import utils as ads_common_utils
@@ -117,6 +123,29 @@ def info(
117123
)
118124

119125

126+
def get_latest_conda_pack(prefix, base_conda) -> str:
127+
"""
128+
get the latest conda pack.
129+
"""
130+
try:
131+
auth = ads.auth.default_signer()
132+
object_storage = oc.OCIClientFactory(**auth).object_storage
133+
objects = object_storage.list_objects(namespace_name=CONDA_BUCKET_NS,
134+
bucket_name=CONDA_BUCKET_NAME,
135+
prefix=prefix).data.objects
136+
137+
def extract_version(obj_name):
138+
match = re.search(rf"{prefix}([\d.]+)/", obj_name)
139+
return tuple(map(int, match.group(1).split("."))) if match else (0,)
140+
141+
latest_obj = max(objects, key=lambda obj: extract_version(obj.name))
142+
return latest_obj.name.split("/")[-1]
143+
except Exception as e:
144+
logger.warning(f"Error while fetching latest conda pack: {e}")
145+
return base_conda
146+
147+
148+
120149
def init(
121150
type: str,
122151
output: Union[str, None] = None,
@@ -157,6 +186,7 @@ def init(
157186

158187
# load operator info
159188
operator_info: OperatorInfo = OperatorLoader.from_uri(uri=type).load()
189+
operator_info.conda = get_latest_conda_pack(operator_info.prefix, operator_info.conda)
160190

161191
# create TMP folder if one is not provided by user
162192
if output:

ads/opctl/operator/common/operator_loader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class OperatorInfo(DataClassSerializable):
154154
conda: str = ""
155155
conda_type: str = ""
156156
path: str = ""
157+
prefix: str = ""
157158
keywords: List[str] = None
158159
backends: List[str] = None
159160
jobs_default_params: JobsDefaultParams = field(default_factory=JobsDefaultParams)

ads/opctl/operator/lowcode/anomaly/MLoperator

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ conda_type: service
44
name: Anomaly Detection Operator
55
conda: anomaly_p310_cpu_x86_64_v1
66
gpu: no
7+
prefix: service_pack/cpu/AI_Forecasting_Operator/
78
keywords:
89
- Anomaly Detection
910
backends:

ads/opctl/operator/lowcode/forecast/MLoperator

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ type: forecast
22
version: v1
33
name: Forecasting Operator
44
conda_type: service
5-
conda: forecast_p310_cpu_x86_64_v4
5+
conda: forecast_p311_cpu_x86_64_v10
66
gpu: no
7+
prefix: service_pack/cpu/AI_Forecasting_Operator/
78
jobs_default_params:
89
shape_name: VM.Standard.E4.Flex
910
ocpus: 16

0 commit comments

Comments
 (0)