Skip to content

Commit c1020f8

Browse files
Addressing review comments
1 parent 87dfe13 commit c1020f8

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

ads/common/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
)
8585

8686

87+
# Metadata artifact path type can be either local path or OSS path. It can also be the content itself.
8788
class MetadataArtifactPathType(ExtendedEnum):
8889
LOCAL = "local"
8990
OSS = "oss"

ads/model/service/oci_datascience_model.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ def _is_model_by_reference(self):
625625
msg="Model needs to be saved to the Model Catalog before the creating custom metadata artifact corresponding to that model"
626626
)
627627
def create_custom_metadata_artifact(
628-
self, metadata_key_name: str, artifact_path: str
628+
self, metadata_key_name: str, artifact_path: str, path_type: str
629629
) -> ModelMetadataArtifactDetails:
630630
"""Creates model custom metadata artifact for specified model.
631631
@@ -653,12 +653,9 @@ def create_custom_metadata_artifact(
653653
}
654654
655655
"""
656-
if not utils.is_path_exists(artifact_path):
657-
raise FileNotFoundError(f"File not found: {artifact_path} . ")
658-
with open(artifact_path, "rb") as f:
659-
contents = f.read()
660-
logger.info(f"The metadata artifact content - {contents}")
661-
656+
contents = self.get_metadata_content(
657+
artifact_path_or_content=artifact_path, path_type=path_type
658+
)
662659
response = self.client.create_model_custom_metadatum_artifact(
663660
self.id,
664661
metadata_key_name,
@@ -671,6 +668,21 @@ def create_custom_metadata_artifact(
671668
return response_data
672669

673670
def get_metadata_content(self, artifact_path_or_content: str, path_type):
671+
"""
672+
returns the content of the metadata artifact
673+
674+
Parameters
675+
----------
676+
artifact_path_or_content: str
677+
The path of the file (local or oss) containing metadata artifact or content.
678+
path_type: str
679+
can be one of local , oss or content
680+
681+
Returns
682+
-------
683+
metadata artifact content
684+
"""
685+
674686
if path_type == utils.MetadataArtifactPathType.CONTENT:
675687
return artifact_path_or_content
676688
elif path_type == utils.MetadataArtifactPathType.LOCAL:
@@ -723,7 +735,9 @@ def create_defined_metadata_artifact(
723735
}
724736
725737
"""
726-
contents = self.get_metadata_content(artifact_path, path_type)
738+
contents = self.get_metadata_content(
739+
artifact_path_or_content=artifact_path, path_type=path_type
740+
)
727741
response = self.client.create_model_defined_metadatum_artifact(
728742
self.id,
729743
metadata_key_name,
@@ -767,7 +781,9 @@ def update_defined_metadata_artifact(
767781
}
768782
769783
"""
770-
contents = self.get_metadata_content(artifact_path, path_type)
784+
contents = self.get_metadata_content(
785+
artifact_path_or_content=artifact_path, path_type=path_type
786+
)
771787
response = self.client.update_model_defined_metadatum_artifact(
772788
self.id,
773789
metadata_key_name,
@@ -811,7 +827,9 @@ def update_custom_metadata_artifact(
811827
}
812828
813829
"""
814-
contents = self.get_metadata_content(artifact_path, path_type)
830+
contents = self.get_metadata_content(
831+
artifact_path_or_content=artifact_path, path_type=path_type
832+
)
815833
response = self.client.update_model_custom_metadatum_artifact(
816834
self.id,
817835
metadata_key_name,

0 commit comments

Comments
 (0)