@@ -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"
@@ -2238,7 +2243,7 @@ def find_model_idx():
2238
2243
def create_custom_metadata_artifact (
2239
2244
self ,
2240
2245
metadata_key_name : str ,
2241
- artifact_path_or_content : str ,
2246
+ artifact_path_or_content : Union [ str , bytes ] ,
2242
2247
path_type : MetadataArtifactPathType = MetadataArtifactPathType .LOCAL ,
2243
2248
) -> ModelMetadataArtifactDetails :
2244
2249
"""Creates model custom metadata artifact for specified model.
@@ -2248,13 +2253,22 @@ def create_custom_metadata_artifact(
2248
2253
metadata_key_name: str
2249
2254
The name of the model custom metadata key
2250
2255
2251
- artifact_path_or_content: str
2252
- The model custom metadata artifact path to be upload. It can also be the actual content of the custom metadata
2256
+ artifact_path_or_content: Union[str,bytes]
2257
+ The model custom metadata artifact path to be uploaded. It can also be the actual content of the custom metadata artifact
2258
+ The type is string when it represents local path or oss path.
2259
+ The type is bytes when it represents content itself
2253
2260
2254
2261
path_type: MetadataArtifactPathType
2255
2262
Can be either of MetadataArtifactPathType.LOCAL , MetadataArtifactPathType.OSS , MetadataArtifactPathType.CONTENT
2256
2263
Specifies what type of path is to be provided for metadata artifact.
2257
- Can be either local , oss or the actual content itself
2264
+
2265
+ Example:
2266
+ >>> ds_model=DataScienceModel.from_id("ocid1.datasciencemodel.iad.xxyxz...")
2267
+ >>> ds_model.create_custom_metadata_artifact(
2268
+ ... "README",
2269
+ ... artifact_path_or_content="/Users/<username>/Downloads/README.md",
2270
+ ... path_type=MetadataArtifactPathType.LOCAL
2271
+ ... )
2258
2272
2259
2273
Returns
2260
2274
-------
@@ -2273,16 +2287,23 @@ def create_custom_metadata_artifact(
2273
2287
}
2274
2288
2275
2289
"""
2290
+ if path_type == MetadataArtifactPathType .CONTENT and not isinstance (
2291
+ artifact_path_or_content , bytes
2292
+ ):
2293
+ raise InvalidArtifactPathTypeOrContentError (
2294
+ f"Invalid type of artifact content: { type (artifact_path_or_content )} . It should be bytes."
2295
+ )
2296
+
2276
2297
return self .dsc_model .create_custom_metadata_artifact (
2277
2298
metadata_key_name = metadata_key_name ,
2278
- artifact_path = artifact_path_or_content ,
2299
+ artifact_path_or_content = artifact_path_or_content ,
2279
2300
path_type = path_type ,
2280
2301
)
2281
2302
2282
2303
def create_defined_metadata_artifact (
2283
2304
self ,
2284
2305
metadata_key_name : str ,
2285
- artifact_path_or_content : str ,
2306
+ artifact_path_or_content : Union [ str , bytes ] ,
2286
2307
path_type : MetadataArtifactPathType = MetadataArtifactPathType .LOCAL ,
2287
2308
) -> ModelMetadataArtifactDetails :
2288
2309
"""Creates model defined metadata artifact for specified model.
@@ -2292,14 +2313,24 @@ def create_defined_metadata_artifact(
2292
2313
metadata_key_name: str
2293
2314
The name of the model defined metadata key
2294
2315
2295
- artifact_path_or_content: str
2296
- The model defined metadata artifact path to be upload. It can also be the actual content of the defined metadata
2316
+ artifact_path_or_content: Union[str,bytes]
2317
+ The model defined metadata artifact path to be uploaded. It can also be the actual content of the defined metadata
2318
+ The type is string when it represents local path or oss path.
2319
+ The type is bytes when it represents content itself
2297
2320
2298
2321
path_type: MetadataArtifactPathType
2299
2322
Can be either of MetadataArtifactPathType.LOCAL , MetadataArtifactPathType.OSS , MetadataArtifactPathType.CONTENT
2300
2323
Specifies what type of path is to be provided for metadata artifact.
2301
2324
Can be either local , oss or the actual content itself
2302
2325
2326
+ Example:
2327
+ >>> ds_model=DataScienceModel.from_id("ocid1.datasciencemodel.iad.xxyxz...")
2328
+ >>> ds_model.create_defined_metadata_artifact(
2329
+ ... "README",
2330
+ ... artifact_path_or_content="oci://path/to/bucket/README.md",
2331
+ ... path_type=MetadataArtifactPathType.OSS
2332
+ ... )
2333
+
2303
2334
Returns
2304
2335
-------
2305
2336
ModelMetadataArtifactDetails
@@ -2317,16 +2348,23 @@ def create_defined_metadata_artifact(
2317
2348
}
2318
2349
2319
2350
"""
2351
+ if path_type == MetadataArtifactPathType .CONTENT and not isinstance (
2352
+ artifact_path_or_content , bytes
2353
+ ):
2354
+ raise InvalidArtifactPathTypeOrContentError (
2355
+ f"Invalid type of artifact content: { type (artifact_path_or_content )} . It should be bytes."
2356
+ )
2357
+
2320
2358
return self .dsc_model .create_defined_metadata_artifact (
2321
2359
metadata_key_name = metadata_key_name ,
2322
- artifact_path = artifact_path_or_content ,
2360
+ artifact_path_or_content = artifact_path_or_content ,
2323
2361
path_type = path_type ,
2324
2362
)
2325
2363
2326
2364
def update_custom_metadata_artifact (
2327
2365
self ,
2328
2366
metadata_key_name : str ,
2329
- artifact_path_or_content : str ,
2367
+ artifact_path_or_content : Union [ str , bytes ] ,
2330
2368
path_type : MetadataArtifactPathType = MetadataArtifactPathType .LOCAL ,
2331
2369
) -> ModelMetadataArtifactDetails :
2332
2370
"""Update model custom metadata artifact for specified model.
@@ -2336,8 +2374,10 @@ def update_custom_metadata_artifact(
2336
2374
metadata_key_name: str
2337
2375
The name of the model custom metadata key
2338
2376
2339
- artifact_path_or_content: str
2340
- The model custom metadata artifact path. It can also be the actual content of the custom metadata
2377
+ artifact_path_or_content: Union[str,bytes]
2378
+ The model custom metadata artifact path to be uploaded. It can also be the actual content of the custom metadata
2379
+ The type is string when it represents local path or oss path.
2380
+ The type is bytes when it represents content itself
2341
2381
2342
2382
path_type: MetadataArtifactPathType
2343
2383
Can be either of MetadataArtifactPathType.LOCAL , MetadataArtifactPathType.OSS , MetadataArtifactPathType.CONTENT
@@ -2361,16 +2401,23 @@ def update_custom_metadata_artifact(
2361
2401
}
2362
2402
2363
2403
"""
2404
+ if path_type == MetadataArtifactPathType .CONTENT and not isinstance (
2405
+ artifact_path_or_content , bytes
2406
+ ):
2407
+ raise InvalidArtifactPathTypeOrContentError (
2408
+ f"Invalid type of artifact content: { type (artifact_path_or_content )} . It should be bytes."
2409
+ )
2410
+
2364
2411
return self .dsc_model .update_custom_metadata_artifact (
2365
2412
metadata_key_name = metadata_key_name ,
2366
- artifact_path = artifact_path_or_content ,
2413
+ artifact_path_or_content = artifact_path_or_content ,
2367
2414
path_type = path_type ,
2368
2415
)
2369
2416
2370
2417
def update_defined_metadata_artifact (
2371
2418
self ,
2372
2419
metadata_key_name : str ,
2373
- artifact_path_or_content : str ,
2420
+ artifact_path_or_content : Union [ str , bytes ] ,
2374
2421
path_type : MetadataArtifactPathType = MetadataArtifactPathType .LOCAL ,
2375
2422
) -> ModelMetadataArtifactDetails :
2376
2423
"""Update model defined metadata artifact for specified model.
@@ -2380,8 +2427,10 @@ def update_defined_metadata_artifact(
2380
2427
metadata_key_name: str
2381
2428
The name of the model defined metadata key
2382
2429
2383
- artifact_path_or_content: str
2384
- The model defined metadata artifact path. It can also be the actual content of the defined metadata
2430
+ artifact_path_or_content: Union[str,bytes]
2431
+ The model defined metadata artifact path to be uploaded. It can also be the actual content of the defined metadata
2432
+ The type is string when it represents local path or oss path.
2433
+ The type is bytes when it represents content itself
2385
2434
2386
2435
path_type: MetadataArtifactPathType
2387
2436
Can be either of MetadataArtifactPathType.LOCAL , MetadataArtifactPathType.OSS , MetadataArtifactPathType.CONTENT
@@ -2405,9 +2454,16 @@ def update_defined_metadata_artifact(
2405
2454
}
2406
2455
2407
2456
"""
2457
+ if path_type == MetadataArtifactPathType .CONTENT and not isinstance (
2458
+ artifact_path_or_content , bytes
2459
+ ):
2460
+ raise InvalidArtifactPathTypeOrContentError (
2461
+ f"Invalid type of artifact content: { type (artifact_path_or_content )} . It should be bytes."
2462
+ )
2463
+
2408
2464
return self .dsc_model .update_defined_metadata_artifact (
2409
2465
metadata_key_name = metadata_key_name ,
2410
- artifact_path = artifact_path_or_content ,
2466
+ artifact_path_or_content = artifact_path_or_content ,
2411
2467
path_type = path_type ,
2412
2468
)
2413
2469
@@ -2442,8 +2498,10 @@ def get_custom_metadata_artifact(
2442
2498
)
2443
2499
artifact_file_path = os .path .join (target_dir , f"{ metadata_key_name } " )
2444
2500
2445
- if not override and os .path .exists (artifact_file_path ):
2446
- raise FileExistsError (f"File already exists: { artifact_file_path } " )
2501
+ if not override and is_path_exists (artifact_file_path ):
2502
+ raise FileExistsError (
2503
+ f"File already exists: { artifact_file_path } . Please use boolean override parameter to override the file content."
2504
+ )
2447
2505
2448
2506
with open (artifact_file_path , "wb" ) as _file :
2449
2507
_file .write (file_content )
@@ -2481,8 +2539,10 @@ def get_defined_metadata_artifact(
2481
2539
)
2482
2540
artifact_file_path = os .path .join (target_dir , f"{ metadata_key_name } " )
2483
2541
2484
- if not override and os .path .exists (artifact_file_path ):
2485
- raise FileExistsError (f"File already exists: { artifact_file_path } " )
2542
+ if not override and is_path_exists (artifact_file_path ):
2543
+ raise FileExistsError (
2544
+ f"File already exists: { artifact_file_path } . Please use boolean override parameter to override the file content."
2545
+ )
2486
2546
2487
2547
with open (artifact_file_path , "wb" ) as _file :
2488
2548
_file .write (file_content )
0 commit comments