19
19
from ads .common import utils
20
20
from ads .common .extended_enum import ExtendedEnum
21
21
from ads .common .object_storage_details import ObjectStorageDetails
22
+ from ads .common .utils import is_path_exists
22
23
from ads .config import (
23
24
AQUA_SERVICE_MODELS_BUCKET as SERVICE_MODELS_BUCKET ,
24
25
)
@@ -74,6 +75,11 @@ def __init__(
74
75
super ().__init__ (msg )
75
76
76
77
78
+ class PathNotFoundError (Exception ):
79
+ def __init__ (self , msg = "The given path doesn't exist." ):
80
+ super ().__init__ (msg )
81
+
82
+
77
83
class ModelFileDescriptionError (Exception ): # pragma: no cover
78
84
def __init__ (self , msg = "Model File Description file is not set up." ):
79
85
super ().__init__ (msg )
@@ -2407,7 +2413,7 @@ def update_defined_metadata_artifact(
2407
2413
2408
2414
def get_custom_metadata_artifact (
2409
2415
self , metadata_key_name : str , target_dir : str , override : bool = False
2410
- ) -> None :
2416
+ ) -> bytes :
2411
2417
"""Downloads model custom metadata artifact content for specified model metadata key.
2412
2418
2413
2419
Parameters
@@ -2424,9 +2430,13 @@ def get_custom_metadata_artifact(
2424
2430
- If False (default), raises a `FileExistsError` if the file exists.
2425
2431
Returns
2426
2432
-------
2427
- None
2433
+ bytes
2434
+ File content of the custom metadata artifact
2428
2435
2429
2436
"""
2437
+ if not is_path_exists (target_dir ):
2438
+ raise PathNotFoundError (f"Path : { target_dir } does not exist" )
2439
+
2430
2440
file_content = self .dsc_model .get_custom_metadata_artifact (
2431
2441
metadata_key_name = metadata_key_name
2432
2442
)
@@ -2438,10 +2448,11 @@ def get_custom_metadata_artifact(
2438
2448
with open (artifact_file_path , "wb" ) as _file :
2439
2449
_file .write (file_content )
2440
2450
logger .debug (f"Artifact downloaded to location - { artifact_file_path } " )
2451
+ return file_content
2441
2452
2442
2453
def get_defined_metadata_artifact (
2443
2454
self , metadata_key_name : str , target_dir : str , override : bool = False
2444
- ) -> None :
2455
+ ) -> bytes :
2445
2456
"""Downloads model defined metadata artifact content for specified model metadata key.
2446
2457
2447
2458
Parameters
@@ -2458,9 +2469,13 @@ def get_defined_metadata_artifact(
2458
2469
- If False (default), raises a `FileExistsError` if the file exists.
2459
2470
Returns
2460
2471
-------
2461
- None
2472
+ bytes
2473
+ File content of the custom metadata artifact
2462
2474
2463
2475
"""
2476
+ if not is_path_exists (target_dir ):
2477
+ raise PathNotFoundError (f"Path : { target_dir } does not exist" )
2478
+
2464
2479
file_content = self .dsc_model .get_defined_metadata_artifact (
2465
2480
metadata_key_name = metadata_key_name
2466
2481
)
@@ -2472,6 +2487,7 @@ def get_defined_metadata_artifact(
2472
2487
with open (artifact_file_path , "wb" ) as _file :
2473
2488
_file .write (file_content )
2474
2489
logger .debug (f"Artifact downloaded to location - { artifact_file_path } " )
2490
+ return file_content
2475
2491
2476
2492
def delete_custom_metadata_artifact (
2477
2493
self , metadata_key_name : str
0 commit comments