@@ -89,6 +89,11 @@ class InvalidArtifactType(Exception): # pragma: no cover
89
89
pass
90
90
91
91
92
+ class InvalidArtifactPathTypeOrContentError (Exception ): # pragma: no cover
93
+ def __init__ (self , msg = "Invalid type of Metdata artifact content" ):
94
+ super ().__init__ (msg )
95
+
96
+
92
97
class CustomerNotificationType (ExtendedEnum ):
93
98
NONE = "NONE"
94
99
ALL = "ALL"
@@ -2267,7 +2272,7 @@ def if_model_custom_metadata_artifact_exist(
2267
2272
def create_custom_metadata_artifact (
2268
2273
self ,
2269
2274
metadata_key_name : str ,
2270
- artifact_path_or_content : str ,
2275
+ artifact_path_or_content : Union [ str , bytes ] ,
2271
2276
path_type : MetadataArtifactPathType = MetadataArtifactPathType .LOCAL ,
2272
2277
) -> ModelMetadataArtifactDetails :
2273
2278
"""Creates model custom metadata artifact for specified model.
@@ -2277,13 +2282,22 @@ def create_custom_metadata_artifact(
2277
2282
metadata_key_name: str
2278
2283
The name of the model custom metadata key
2279
2284
2280
- artifact_path_or_content: str
2281
- The model custom metadata artifact path to be upload. It can also be the actual content of the custom metadata
2285
+ artifact_path_or_content: Union[str,bytes]
2286
+ The model custom metadata artifact path to be uploaded. It can also be the actual content of the custom metadata artifact
2287
+ The type is string when it represents local path or oss path.
2288
+ The type is bytes when it represents content itself
2282
2289
2283
2290
path_type: MetadataArtifactPathType
2284
2291
Can be either of MetadataArtifactPathType.LOCAL , MetadataArtifactPathType.OSS , MetadataArtifactPathType.CONTENT
2285
2292
Specifies what type of path is to be provided for metadata artifact.
2286
- Can be either local , oss or the actual content itself
2293
+
2294
+ Example:
2295
+ >>> ds_model=DataScienceModel.from_id("ocid1.datasciencemodel.iad.xxyxz...")
2296
+ >>> ds_model.create_custom_metadata_artifact(
2297
+ ... "README",
2298
+ ... artifact_path_or_content="/Users/<username>/Downloads/README.md",
2299
+ ... path_type=MetadataArtifactPathType.LOCAL
2300
+ ... )
2287
2301
2288
2302
Returns
2289
2303
-------
@@ -2302,16 +2316,23 @@ def create_custom_metadata_artifact(
2302
2316
}
2303
2317
2304
2318
"""
2319
+ if path_type == MetadataArtifactPathType .CONTENT and not isinstance (
2320
+ artifact_path_or_content , bytes
2321
+ ):
2322
+ raise InvalidArtifactPathTypeOrContentError (
2323
+ f"Invalid type of artifact content: { type (artifact_path_or_content )} . It should be bytes."
2324
+ )
2325
+
2305
2326
return self .dsc_model .create_custom_metadata_artifact (
2306
2327
metadata_key_name = metadata_key_name ,
2307
- artifact_path = artifact_path_or_content ,
2328
+ artifact_path_or_content = artifact_path_or_content ,
2308
2329
path_type = path_type ,
2309
2330
)
2310
2331
2311
2332
def create_defined_metadata_artifact (
2312
2333
self ,
2313
2334
metadata_key_name : str ,
2314
- artifact_path_or_content : str ,
2335
+ artifact_path_or_content : Union [ str , bytes ] ,
2315
2336
path_type : MetadataArtifactPathType = MetadataArtifactPathType .LOCAL ,
2316
2337
) -> ModelMetadataArtifactDetails :
2317
2338
"""Creates model defined metadata artifact for specified model.
@@ -2321,14 +2342,24 @@ def create_defined_metadata_artifact(
2321
2342
metadata_key_name: str
2322
2343
The name of the model defined metadata key
2323
2344
2324
- artifact_path_or_content: str
2325
- The model defined metadata artifact path to be upload. It can also be the actual content of the defined metadata
2345
+ artifact_path_or_content: Union[str,bytes]
2346
+ The model defined metadata artifact path to be uploaded. It can also be the actual content of the defined metadata
2347
+ The type is string when it represents local path or oss path.
2348
+ The type is bytes when it represents content itself
2326
2349
2327
2350
path_type: MetadataArtifactPathType
2328
2351
Can be either of MetadataArtifactPathType.LOCAL , MetadataArtifactPathType.OSS , MetadataArtifactPathType.CONTENT
2329
2352
Specifies what type of path is to be provided for metadata artifact.
2330
2353
Can be either local , oss or the actual content itself
2331
2354
2355
+ Example:
2356
+ >>> ds_model=DataScienceModel.from_id("ocid1.datasciencemodel.iad.xxyxz...")
2357
+ >>> ds_model.create_defined_metadata_artifact(
2358
+ ... "README",
2359
+ ... artifact_path_or_content="oci://path/to/bucket/README.md",
2360
+ ... path_type=MetadataArtifactPathType.OSS
2361
+ ... )
2362
+
2332
2363
Returns
2333
2364
-------
2334
2365
ModelMetadataArtifactDetails
@@ -2346,16 +2377,23 @@ def create_defined_metadata_artifact(
2346
2377
}
2347
2378
2348
2379
"""
2380
+ if path_type == MetadataArtifactPathType .CONTENT and not isinstance (
2381
+ artifact_path_or_content , bytes
2382
+ ):
2383
+ raise InvalidArtifactPathTypeOrContentError (
2384
+ f"Invalid type of artifact content: { type (artifact_path_or_content )} . It should be bytes."
2385
+ )
2386
+
2349
2387
return self .dsc_model .create_defined_metadata_artifact (
2350
2388
metadata_key_name = metadata_key_name ,
2351
- artifact_path = artifact_path_or_content ,
2389
+ artifact_path_or_content = artifact_path_or_content ,
2352
2390
path_type = path_type ,
2353
2391
)
2354
2392
2355
2393
def update_custom_metadata_artifact (
2356
2394
self ,
2357
2395
metadata_key_name : str ,
2358
- artifact_path_or_content : str ,
2396
+ artifact_path_or_content : Union [ str , bytes ] ,
2359
2397
path_type : MetadataArtifactPathType = MetadataArtifactPathType .LOCAL ,
2360
2398
) -> ModelMetadataArtifactDetails :
2361
2399
"""Update model custom metadata artifact for specified model.
@@ -2365,8 +2403,10 @@ def update_custom_metadata_artifact(
2365
2403
metadata_key_name: str
2366
2404
The name of the model custom metadata key
2367
2405
2368
- artifact_path_or_content: str
2369
- The model custom metadata artifact path. It can also be the actual content of the custom metadata
2406
+ artifact_path_or_content: Union[str,bytes]
2407
+ The model custom metadata artifact path to be uploaded. It can also be the actual content of the custom metadata
2408
+ The type is string when it represents local path or oss path.
2409
+ The type is bytes when it represents content itself
2370
2410
2371
2411
path_type: MetadataArtifactPathType
2372
2412
Can be either of MetadataArtifactPathType.LOCAL , MetadataArtifactPathType.OSS , MetadataArtifactPathType.CONTENT
@@ -2390,16 +2430,23 @@ def update_custom_metadata_artifact(
2390
2430
}
2391
2431
2392
2432
"""
2433
+ if path_type == MetadataArtifactPathType .CONTENT and not isinstance (
2434
+ artifact_path_or_content , bytes
2435
+ ):
2436
+ raise InvalidArtifactPathTypeOrContentError (
2437
+ f"Invalid type of artifact content: { type (artifact_path_or_content )} . It should be bytes."
2438
+ )
2439
+
2393
2440
return self .dsc_model .update_custom_metadata_artifact (
2394
2441
metadata_key_name = metadata_key_name ,
2395
- artifact_path = artifact_path_or_content ,
2442
+ artifact_path_or_content = artifact_path_or_content ,
2396
2443
path_type = path_type ,
2397
2444
)
2398
2445
2399
2446
def update_defined_metadata_artifact (
2400
2447
self ,
2401
2448
metadata_key_name : str ,
2402
- artifact_path_or_content : str ,
2449
+ artifact_path_or_content : Union [ str , bytes ] ,
2403
2450
path_type : MetadataArtifactPathType = MetadataArtifactPathType .LOCAL ,
2404
2451
) -> ModelMetadataArtifactDetails :
2405
2452
"""Update model defined metadata artifact for specified model.
@@ -2409,8 +2456,10 @@ def update_defined_metadata_artifact(
2409
2456
metadata_key_name: str
2410
2457
The name of the model defined metadata key
2411
2458
2412
- artifact_path_or_content: str
2413
- The model defined metadata artifact path. It can also be the actual content of the defined metadata
2459
+ artifact_path_or_content: Union[str,bytes]
2460
+ The model defined metadata artifact path to be uploaded. It can also be the actual content of the defined metadata
2461
+ The type is string when it represents local path or oss path.
2462
+ The type is bytes when it represents content itself
2414
2463
2415
2464
path_type: MetadataArtifactPathType
2416
2465
Can be either of MetadataArtifactPathType.LOCAL , MetadataArtifactPathType.OSS , MetadataArtifactPathType.CONTENT
@@ -2434,9 +2483,16 @@ def update_defined_metadata_artifact(
2434
2483
}
2435
2484
2436
2485
"""
2486
+ if path_type == MetadataArtifactPathType .CONTENT and not isinstance (
2487
+ artifact_path_or_content , bytes
2488
+ ):
2489
+ raise InvalidArtifactPathTypeOrContentError (
2490
+ f"Invalid type of artifact content: { type (artifact_path_or_content )} . It should be bytes."
2491
+ )
2492
+
2437
2493
return self .dsc_model .update_defined_metadata_artifact (
2438
2494
metadata_key_name = metadata_key_name ,
2439
- artifact_path = artifact_path_or_content ,
2495
+ artifact_path_or_content = artifact_path_or_content ,
2440
2496
path_type = path_type ,
2441
2497
)
2442
2498
@@ -2471,7 +2527,7 @@ def get_custom_metadata_artifact(
2471
2527
)
2472
2528
artifact_file_path = os .path .join (target_dir , f"{ metadata_key_name } " )
2473
2529
2474
- if not override and os . path . exists (artifact_file_path ):
2530
+ if not override and is_path_exists (artifact_file_path ):
2475
2531
raise FileExistsError (f"File already exists: { artifact_file_path } " )
2476
2532
2477
2533
with open (artifact_file_path , "wb" ) as _file :
@@ -2510,7 +2566,7 @@ def get_defined_metadata_artifact(
2510
2566
)
2511
2567
artifact_file_path = os .path .join (target_dir , f"{ metadata_key_name } " )
2512
2568
2513
- if not override and os . path . exists (artifact_file_path ):
2569
+ if not override and is_path_exists (artifact_file_path ):
2514
2570
raise FileExistsError (f"File already exists: { artifact_file_path } " )
2515
2571
2516
2572
with open (artifact_file_path , "wb" ) as _file :
0 commit comments