Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRCC] Create and Update Metadata artifact content changes #1129

Merged
merged 7 commits into from
Mar 25, 2025

Conversation

kumar-shivam-ranjan
Copy link
Member

@kumar-shivam-ranjan kumar-shivam-ranjan commented Mar 21, 2025

Description

This PR is intended to improve API for creating and updating metadata artifact which was introduced as part of MS enhancements.

Issue

While uploading metadata artifact , the type of content should always be bytes. Earlier it was both bytes and strings.

Example

When uploading the content via local path

from ads.model.common.utils import MetadataArtifactPathType
from ads.model.datascience_model import DataScienceModel

ds_model=DataScienceModel.from_id("ocid1.datasciencemodel.oc1.iad.xxyz")

ds_model.create_defined_metadata_artifact(
    "README",
    artifact_path_or_content="/Users/<username>/Downloads/README.md",
    path_type=MetadataArtifactPathType.LOCAL
)

When uploading the content via OSS path

from ads.model.common.utils import MetadataArtifactPathType
from ads.model.datascience_model import DataScienceModel

ds_model=DataScienceModel.from_id("ocid1.datasciencemodel.oc1.iad.xxyz")

ds_model.create_defined_metadata_artifact(
    "README",
    artifact_path_or_content="oci://path/to/oss/bucket/README.md",
    path_type=MetadataArtifactPathType.OSS
)

When uploading the content itself

from ads.model.common.utils import MetadataArtifactPathType
from ads.model.datascience_model import DataScienceModel

ds_model=DataScienceModel.from_id(
    "ocid1.datasciencemodel.oc1.iad.amaaaaaav66vvniavg7xmekk2igrj6oybxgswetlmztgaqrz274jryp4hf7a"
)
with open("/Users/kumarran/Downloads/README.md","rb") as f:
    content=f.read()

# type of content here is bytes
ds_model.create_defined_metadata_artifact(
    "README",
    artifact_path_or_content=content,
    path_type=MetadataArtifactPathType.CONTENT
)

Unit tests

Screenshot 2025-03-21 at 5 37 51 PM

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Mar 21, 2025
Copy link

📌 Cov diff with main:

Coverage-8%

📌 Overall coverage:

Coverage-58.49%

Copy link

📌 Cov diff with main:

Coverage-8%

📌 Overall coverage:

Coverage-58.49%

Copy link

📌 Cov diff with main:

Coverage-8%

📌 Overall coverage:

Coverage-58.49%

mrDzurb
mrDzurb previously approved these changes Mar 25, 2025
@@ -2442,7 +2498,7 @@ def get_custom_metadata_artifact(
)
artifact_file_path = os.path.join(target_dir, f"{metadata_key_name}")

if not override and os.path.exists(artifact_file_path):
if not override and is_path_exists(artifact_file_path):
raise FileExistsError(f"File already exists: {artifact_file_path}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we say to use the override param to override?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can. Will update the error message.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

contents = str(
read_file(file_path=artifact_path_or_content, auth=default_signer())
)
contents = read_file(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, why do we want to distinguish between local and OSS? Can't we use the same logic for both?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to change the read_file function defintion in ads.common.utils since it is already used in many other places.
read_file returns string content of the file and we need bytes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now , if think we could have used same logic though without changing read_file function definition.
Updated it. Thanks!
@mrDzurb

Copy link

📌 Cov diff with main:

Coverage-25%

📌 Overall coverage:

Coverage-58.50%

lu-ohai
lu-ohai previously approved these changes Mar 25, 2025
self, artifact_path_or_content: str, path_type: MetadataArtifactPathType
self,
artifact_path_or_content: Union[str, bytes],
path_type: MetadataArtifactPathType,
):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a return statement here to be more clear:

def get_metadata_content(
        self,
        artifact_path_or_content: Union[str, bytes],
        path_type: MetadataArtifactPathType,
) -> Union[str, bytes]:

Copy link
Member Author

@kumar-shivam-ranjan kumar-shivam-ranjan Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_metadata_content always returns bytes. Updated. Thanks!

Copy link

📌 Cov diff with main:

Coverage-25%

📌 Overall coverage:

Coverage-58.50%

@kumar-shivam-ranjan kumar-shivam-ranjan merged commit ba5fb25 into main Mar 25, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants