-
Notifications
You must be signed in to change notification settings - Fork 369
feat: Add samples for Metadata context list, get, and create #1525
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
Merged
SinaChavoshi
merged 18 commits into
googleapis:main
from
SinaChavoshi:sdk_samples_list_get_create_for_context
Jul 25, 2022
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
338e4b1
feat: Add samples for context list,get and create
SinaChavoshi 7a139a8
fix lint issues.
SinaChavoshi ce2af42
Merge remote-tracking branch 'upstream/main' into sdk_samples_list_ge…
SinaChavoshi 41a21d5
Change import path to aiplatform.Context
SinaChavoshi 780374a
Merge branch 'main' into sdk_samples_list_get_create_for_context
SinaChavoshi 257f204
Merge branch 'main' into sdk_samples_list_get_create_for_context
SinaChavoshi be8f59f
Merge branch 'main' into sdk_samples_list_get_create_for_context
SinaChavoshi dd50457
Merge branch 'main' into sdk_samples_list_get_create_for_context
SinaChavoshi ef23369
Fix create mock.
SinaChavoshi b617e3a
Merge branch 'main' into sdk_samples_list_get_create_for_context
SinaChavoshi 5a4093c
remove duplicate mock method
SinaChavoshi 8e4c718
Merge branch 'main' into sdk_samples_list_get_create_for_context
SinaChavoshi f9b30e4
Merge branch 'main' into sdk_samples_list_get_create_for_context
SinaChavoshi 32fba4f
Update samples/model-builder/experiment_tracking/get_context_sample_t…
SinaChavoshi 8544307
Update samples/model-builder/experiment_tracking/list_context_sample_…
SinaChavoshi 7066313
Update samples/model-builder/experiment_tracking/list_context_sample_…
SinaChavoshi 47620a1
Update samples/model-builder/experiment_tracking/get_context_sample_t…
SinaChavoshi 3c461b1
update formatting and comments based on review feedback
SinaChavoshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
samples/model-builder/experiment_tracking/create_context_with_sdk_sample.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright 2022 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from typing import Any, Dict, Optional | ||
|
||
from google.cloud import aiplatform | ||
from google.cloud.aiplatform.metadata.schema.system import context_schema | ||
|
||
|
||
# [START aiplatform_sdk_create_context_with_sdk_sample] | ||
def create_context_sample( | ||
display_name: str, | ||
project: str, | ||
location: str, | ||
context_id: Optional[str] = None, | ||
metadata: Optional[Dict[str, Any]] = None, | ||
schema_version: Optional[str] = None, | ||
description: Optional[str] = None, | ||
): | ||
aiplatform.init(project=project, location=location) | ||
|
||
return context_schema.Experiment( | ||
display_name=display_name, | ||
context_id=context_id, | ||
metadata=metadata, | ||
schema_version=schema_version, | ||
description=description, | ||
).create() | ||
|
||
# [END aiplatform_sdk_create_context_with_sdk_sample] |
38 changes: 38 additions & 0 deletions
38
samples/model-builder/experiment_tracking/create_context_with_sdk_sample_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2022 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import create_context_with_sdk_sample | ||
|
||
import test_constants as constants | ||
|
||
|
||
def test_create_context_sample( | ||
mock_sdk_init, mock_create_schema_base_context, mock_context, | ||
): | ||
exc = create_context_with_sdk_sample.create_context_sample( | ||
display_name=constants.DISPLAY_NAME, | ||
project=constants.PROJECT, | ||
location=constants.LOCATION, | ||
context_id=constants.RESOURCE_ID, | ||
metadata=constants.METADATA, | ||
schema_version=constants.SCHEMA_VERSION, | ||
description=constants.DESCRIPTION, | ||
) | ||
|
||
mock_sdk_init.assert_called_with( | ||
project=constants.PROJECT, location=constants.LOCATION, | ||
) | ||
|
||
mock_create_schema_base_context.assert_called_with() | ||
assert exc is mock_context |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,4 @@ def get_artifact_sample( | |
|
||
return artifact | ||
|
||
|
||
# [END aiplatform_sdk_get_artifact_sample] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
samples/model-builder/experiment_tracking/get_context_sample.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright 2022 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from google.cloud import aiplatform | ||
|
||
|
||
# [START aiplatform_sdk_get_context_sample] | ||
def get_context_sample( | ||
context_id: str, | ||
project: str, | ||
location: str, | ||
): | ||
context = aiplatform.Context.get( | ||
resource_id=context_id, project=project, location=location) | ||
return context | ||
|
||
# [END aiplatform_sdk_get_context_sample] |
33 changes: 33 additions & 0 deletions
33
samples/model-builder/experiment_tracking/get_context_sample_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2022 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import get_context_sample | ||
|
||
import test_constants as constants | ||
|
||
|
||
def test_get_context_sample(mock_context, mock_context_get): | ||
context = get_context_sample.get_context_sample( | ||
context_id=constants.RESOURCE_ID, | ||
project=constants.PROJECT, | ||
location=constants.LOCATION, | ||
) | ||
|
||
mock_context_get.assert_called_with( | ||
resource_id=constants.RESOURCE_ID, | ||
project=constants.PROJECT, | ||
location=constants.LOCATION, | ||
) | ||
|
||
assert context is mock_context |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.