-
Notifications
You must be signed in to change notification settings - Fork 6.5k
feat(generativeai): Create genai_sdk_supervised_checkpoints_test_exa… #13347
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,63 @@ | ||||||||||||||
# Copyright 2024 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 os | ||||||||||||||
|
||||||||||||||
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
def genai_sdk_gemini_checkpoints_test_tuned_endpoint() -> str: | ||||||||||||||
# [START genaisdk_gemini_checkpoints_test_tuned_endpoint] | ||||||||||||||
from google import genai | ||||||||||||||
|
||||||||||||||
# TODO(developer): Update and un-comment below lines | ||||||||||||||
# PROJECT_ID = "your-project-id" | ||||||||||||||
client = genai.Client( | ||||||||||||||
vertexai=True, | ||||||||||||||
project=PROJECT_ID, | ||||||||||||||
location="us-central1", | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
name = "projects/12345678/locations/us-central1/tuningJobs/123456789012345" | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||
tuning_job = client.tunings.get(name=name) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding error handling in case the tuning job is not found or if there are issues retrieving it. This would make the example more robust.
Suggested change
|
||||||||||||||
|
||||||||||||||
contents = "Why is the sky blue?" | ||||||||||||||
|
||||||||||||||
# Tests the default checkpoint | ||||||||||||||
response = client.models.generate_content( | ||||||||||||||
model=tuning_job.tuned_model.endpoint, | ||||||||||||||
contents=contents, | ||||||||||||||
) | ||||||||||||||
print(response.text) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||
|
||||||||||||||
# Tests Checkpoint 1 | ||||||||||||||
checkpoint1_response = client.models.generate_content( | ||||||||||||||
model=tuning_job.tuned_model.checkpoints[0].endpoint, | ||||||||||||||
contents=contents, | ||||||||||||||
) | ||||||||||||||
print(checkpoint1_response.text) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||
|
||||||||||||||
# Tests Checkpoint 2 | ||||||||||||||
checkpoint2_response = client.models.generate_content( | ||||||||||||||
model=tuning_job.tuned_model.checkpoints[1].endpoint, | ||||||||||||||
contents=contents, | ||||||||||||||
) | ||||||||||||||
print(checkpoint2_response.text) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||
|
||||||||||||||
# [END genaisdk_gemini_checkpoints_test_tuned_endpoint] | ||||||||||||||
return response.text | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
if __name__ == "__main__": | ||||||||||||||
genai_sdk_gemini_checkpoints_test_tuned_endpoint() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good practice to provide a more descriptive comment explaining why the developer needs to update and uncomment these lines. For example, specify what
your-project-id
refers to and how to obtain it.