Skip to content

Commit d681e17

Browse files
committed
Added methods for aqua-model store apis change
1 parent ac40648 commit d681e17

File tree

5 files changed

+668
-8
lines changed

5 files changed

+668
-8
lines changed

ads/model/datascience_model.py

Lines changed: 256 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import os
1111
import shutil
1212
import tempfile
13+
import uuid
1314
from copy import deepcopy
1415
from typing import Dict, List, Optional, Tuple, Union
16+
from zipfile import ZipFile
1517

1618
import pandas
1719
import yaml
@@ -1571,7 +1573,7 @@ def delete(
15711573

15721574
@classmethod
15731575
def list(
1574-
cls, compartment_id: str = None, project_id: str = None, **kwargs
1576+
cls, compartment_id: str = None, project_id: str = None,category: str = "USER", **kwargs
15751577
) -> List["DataScienceModel"]:
15761578
"""Lists datascience models in a given compartment.
15771579
@@ -1581,6 +1583,8 @@ def list(
15811583
The compartment OCID.
15821584
project_id: (str, optional). Defaults to `None`.
15831585
The project OCID.
1586+
category: (str, optional). Defaults to `USER`.
1587+
The category of Model.
15841588
kwargs
15851589
Additional keyword arguments for filtering models.
15861590
@@ -1592,13 +1596,13 @@ def list(
15921596
return [
15931597
cls()._update_from_oci_dsc_model(model)
15941598
for model in OCIDataScienceModel.list_resource(
1595-
compartment_id, project_id=project_id, **kwargs
1599+
compartment_id, project_id=project_id, category=category, **kwargs
15961600
)
15971601
]
15981602

15991603
@classmethod
16001604
def list_df(
1601-
cls, compartment_id: str = None, project_id: str = None, **kwargs
1605+
cls, compartment_id: str = None, project_id: str = None, category: str = "USER", **kwargs
16021606
) -> "pandas.DataFrame":
16031607
"""Lists datascience models in a given compartment.
16041608
@@ -1608,6 +1612,8 @@ def list_df(
16081612
The compartment OCID.
16091613
project_id: (str, optional). Defaults to `None`.
16101614
The project OCID.
1615+
category: (str, optional). Defaults to `None`.
1616+
The category of Model.
16111617
kwargs
16121618
Additional keyword arguments for filtering models.
16131619
@@ -1618,7 +1624,7 @@ def list_df(
16181624
"""
16191625
records = []
16201626
for model in OCIDataScienceModel.list_resource(
1621-
compartment_id, project_id=project_id, **kwargs
1627+
compartment_id, project_id=project_id, category=category, **kwargs
16221628
):
16231629
records.append(
16241630
{
@@ -2193,3 +2199,249 @@ def find_model_idx():
21932199
else:
21942200
# model found case
21952201
self.model_file_description["models"].pop(modelSearchIdx)
2202+
2203+
def create_custom_metadata_artifact(self, model_ocid: str, metadata_key_name: str, artifact_path: str) -> dict:
2204+
"""Creates model custom metadata artifact for specified model.
2205+
2206+
Parameters
2207+
----------
2208+
model_ocid: str
2209+
The `OCID`__ of the model.
2210+
__ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm
2211+
2212+
metadata_key_name: str
2213+
The name of the model metadatum in the metadata.
2214+
2215+
artifact_path: str
2216+
The model custom metadata artifact path to be upload.
2217+
Returns
2218+
-------
2219+
Dict
2220+
The model custom metadata artifact creation info.
2221+
Example:
2222+
{
2223+
'Date': 'Mon, 02 Dec 2024 06:38:24 GMT',
2224+
'opc-request-id': 'E4F7',
2225+
'ETag': '77156317-8bb9-4c4a-882b-0d85f8140d93',
2226+
'X-Content-Type-Options': 'nosniff',
2227+
'Content-Length': '4029958',
2228+
'Vary': 'Origin',
2229+
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
2230+
'status': 204
2231+
}
2232+
2233+
"""
2234+
return self.dsc_model.create_custom_metadata_artifact(model_ocid=model_ocid, metadata_key_name=metadata_key_name,
2235+
artifact_path=artifact_path)
2236+
2237+
2238+
def create_defined_metadata_artifact(self, model_ocid: str, metadata_key_name: str, artifact_path: str) -> dict:
2239+
"""Creates model defined metadata artifact for specified model.
2240+
2241+
Parameters
2242+
----------
2243+
model_ocid: str
2244+
The `OCID`__ of the model.
2245+
__ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm
2246+
2247+
metadata_key_name: str
2248+
The name of the model metadatum in the metadata.
2249+
2250+
artifact_path: str
2251+
The model custom metadata artifact path to be upload.
2252+
Returns
2253+
-------
2254+
The model defined metadata artifact creation info.
2255+
Example:
2256+
{
2257+
'Date': 'Mon, 02 Dec 2024 06:38:24 GMT',
2258+
'opc-request-id': 'E4F7',
2259+
'ETag': '77156317-8bb9-4c4a-882b-0d85f8140d93',
2260+
'X-Content-Type-Options': 'nosniff',
2261+
'Content-Length': '4029958',
2262+
'Vary': 'Origin',
2263+
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
2264+
'status': 204
2265+
}
2266+
2267+
"""
2268+
return self.dsc_model.create_defined_metadata_artifact(model_ocid=model_ocid, metadata_key_name=metadata_key_name,
2269+
artifact_path=artifact_path)
2270+
2271+
2272+
def update_custom_metadata_artifact(self, model_ocid: str, metadata_key_name: str, artifact_path: str) -> dict:
2273+
"""Update model custom metadata artifact for specified model.
2274+
2275+
Parameters
2276+
----------
2277+
model_ocid: str
2278+
The `OCID`__ of the model.
2279+
__ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm
2280+
2281+
metadata_key_name: str
2282+
The name of the model metadatum in the metadata.
2283+
2284+
artifact_path: str
2285+
The model custom metadata artifact path to be upload.
2286+
Returns
2287+
-------
2288+
Dict
2289+
The model custom metadata artifact update info.
2290+
Example:
2291+
{
2292+
'Date': 'Mon, 02 Dec 2024 06:38:24 GMT',
2293+
'opc-request-id': 'E4F7',
2294+
'ETag': '77156317-8bb9-4c4a-882b-0d85f8140d93',
2295+
'X-Content-Type-Options': 'nosniff',
2296+
'Content-Length': '4029958',
2297+
'Vary': 'Origin',
2298+
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
2299+
'status': 204
2300+
}
2301+
2302+
"""
2303+
return self.dsc_model.update_custom_metadata_artifact(model_ocid=model_ocid, metadata_key_name=metadata_key_name,
2304+
artifact_path=artifact_path)
2305+
2306+
2307+
def update_defined_metadata_artifact(self, model_ocid: str, metadata_key_name: str, artifact_path: str) -> dict:
2308+
"""Update model defined metadata artifact for specified model.
2309+
2310+
Parameters
2311+
----------
2312+
model_ocid: str
2313+
The `OCID`__ of the model.
2314+
__ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm
2315+
2316+
metadata_key_name: str
2317+
The name of the model metadatum in the metadata.
2318+
2319+
artifact_path: str
2320+
The model defined metadata artifact path to be upload.
2321+
Returns
2322+
-------
2323+
Dict
2324+
The model defined metadata artifact update info.
2325+
Example:
2326+
{
2327+
'Date': 'Mon, 02 Dec 2024 06:38:24 GMT',
2328+
'opc-request-id': 'E4F7',
2329+
'ETag': '77156317-8bb9-4c4a-882b-0d85f8140d93',
2330+
'X-Content-Type-Options': 'nosniff',
2331+
'Content-Length': '4029958',
2332+
'Vary': 'Origin',
2333+
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
2334+
'status': 204
2335+
}
2336+
2337+
"""
2338+
return self.dsc_model.update_defined_metadata_artifact(model_ocid=model_ocid, metadata_key_name=metadata_key_name,
2339+
artifact_path=artifact_path)
2340+
2341+
def get_custom_metadata_artifact(self, model_ocid: str, metadata_key_name: str, target_dir: str) -> None:
2342+
"""Downloads model custom metadata artifact content for specified model metadata key.
2343+
2344+
Parameters
2345+
----------
2346+
model_ocid: str
2347+
The `OCID`__ of the model.
2348+
__ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm
2349+
2350+
metadata_key_name: str
2351+
The name of the model metadatum in the metadata.
2352+
Returns
2353+
-------
2354+
BytesIO
2355+
custom metadata artifact content
2356+
2357+
"""
2358+
file_content = self.dsc_model.get_custom_metadata_artifact(model_ocid=model_ocid,
2359+
metadata_key_name=metadata_key_name)
2360+
artifact_file_path = os.path.join(
2361+
target_dir, f"{metadata_key_name}"
2362+
)
2363+
with open(artifact_file_path, "wb") as _file:
2364+
_file.write(file_content)
2365+
print(f"Artifact downloaded to location - {artifact_file_path}")
2366+
2367+
def get_defined_metadata_artifact(self, model_ocid: str, metadata_key_name: str, target_dir: str) -> None:
2368+
"""Downloads model defined metadata artifact content for specified model metadata key.
2369+
2370+
Parameters
2371+
----------
2372+
model_ocid: str
2373+
The `OCID`__ of the model.
2374+
__ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm
2375+
2376+
metadata_key_name: str
2377+
The name of the model metadatum in the metadata.
2378+
Returns
2379+
-------
2380+
BytesIO
2381+
Defined metadata artifact content
2382+
2383+
"""
2384+
file_content = self.dsc_model.get_defined_metadata_artifact(model_ocid=model_ocid,
2385+
metadata_key_name=metadata_key_name)
2386+
artifact_file_path = os.path.join(
2387+
target_dir, f"{metadata_key_name}"
2388+
)
2389+
with open(artifact_file_path, "wb") as _file:
2390+
_file.write(file_content)
2391+
print(f"Artifact downloaded to location - {artifact_file_path}")
2392+
2393+
def delete_custom_metadata_artifact(self, model_ocid: str, metadata_key_name: str) -> dict:
2394+
"""Deletes model custom metadata artifact for specified model metadata key.
2395+
2396+
Parameters
2397+
----------
2398+
model_ocid: str
2399+
The `OCID`__ of the model.
2400+
__ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm
2401+
2402+
metadata_key_name: str
2403+
The name of the model metadatum in the metadata.
2404+
Returns
2405+
-------
2406+
Dict
2407+
The model custom metadata artifact delete call info.
2408+
Example:
2409+
{
2410+
'Date': 'Mon, 02 Dec 2024 06:38:24 GMT',
2411+
'opc-request-id': 'E4F7',
2412+
'X-Content-Type-Options': 'nosniff',
2413+
'Vary': 'Origin',
2414+
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
2415+
'status': 204
2416+
}
2417+
2418+
"""
2419+
return self.dsc_model.delete_custom_metadata_artifact(model_ocid=model_ocid, metadata_key_name=metadata_key_name)
2420+
2421+
def delete_defined_metadata_artifact(self, model_ocid: str, metadata_key_name: str) -> dict:
2422+
"""Deletes model defined metadata artifact for specified model metadata key.
2423+
2424+
Parameters
2425+
----------
2426+
model_ocid: str
2427+
The `OCID`__ of the model.
2428+
__ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm
2429+
2430+
metadata_key_name: str
2431+
The name of the model metadatum in the metadata.
2432+
Returns
2433+
-------
2434+
Dict
2435+
The model defined metadata artifact delete call info.
2436+
Example:
2437+
{
2438+
'Date': 'Mon, 02 Dec 2024 06:38:24 GMT',
2439+
'opc-request-id': 'E4F7',
2440+
'X-Content-Type-Options': 'nosniff',
2441+
'Vary': 'Origin',
2442+
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
2443+
'status': 204
2444+
}
2445+
2446+
"""
2447+
return self.dsc_model.delete_defined_metadata_artifact(model_ocid=model_ocid, metadata_key_name=metadata_key_name)

ads/model/model_version_set.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ def kind(self) -> str:
454454
return "modelVersionSet"
455455

456456
@classmethod
457-
def list(cls, compartment_id: str = None, **kwargs) -> List["ModelVersionSet"]:
457+
def list(cls, compartment_id: str = None, category: Optional[str] = "USER", **kwargs) -> List["ModelVersionSet"]:
458458
"""
459459
List model version sets in a given compartment.
460460
@@ -473,7 +473,7 @@ def list(cls, compartment_id: str = None, **kwargs) -> List["ModelVersionSet"]:
473473
return [
474474
cls.from_dsc_model_version_set(model_version_set)
475475
for model_version_set in DataScienceModelVersionSet.list_resource(
476-
compartment_id, **kwargs
476+
compartment_id, category, **kwargs
477477
)
478478
]
479479

0 commit comments

Comments
 (0)