-
Notifications
You must be signed in to change notification settings - Fork 6.5k
feat(generativeai): Create genai_sdk_supervised_example.py #13350
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
base: main
Are you sure you want to change the base?
Conversation
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.
Hello @yishan-pu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request adds a new example, genai_sdk_supervised_example.py
, demonstrating how to create a tuning job using the Gen AI SDK. The example showcases the basic steps involved in tuning a Gemini model, including setting up the client, specifying the base model and training dataset, configuring the tuning job, and monitoring its progress. It also prints information about the tuned model, its endpoint, the associated experiment, and any checkpoints that were created.
Highlights
- New Example: Introduces
genai_sdk_supervised_example.py
to illustrate the creation of a tuning job with the Gen AI SDK. - Tuning Job Configuration: Demonstrates how to configure a tuning job, including specifying the base model, training dataset, and display name.
- Monitoring and Output: Shows how to monitor the tuning job's progress and print information about the tuned model, endpoint, experiment, and checkpoints.
Changelog
- generative_ai/model_tuning/genai_sdk_supervised_example.py
- Created a new file containing an example of how to create a tuning job using the Gen AI SDK.
- The example uses the
gemini-2.0-flash-lite-001
base model and a sample training dataset from Google Cloud Storage. - The example includes code to monitor the tuning job's state and print information about the tuned model and its checkpoints.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
A model to tune,
A dataset to refine,
AI's gentle art.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
The code introduces a new example for creating a tuning job using the Gen AI SDK. The example is well-structured and provides a basic implementation for tuning a Gemini model. However, there are a few areas that could be improved for clarity and robustness.
Summary of Findings
- Missing Error Handling: The code lacks proper error handling. The example should include error handling for API calls and other potential failures to ensure the application is robust.
- TODO Comment: The
TODO
comment should be addressed by providing a default value or a clear instruction on how to set thePROJECT_ID
environment variable. - Hardcoded Values: The example uses hardcoded values for the base model and training dataset. These values should be configurable or clearly documented to allow users to easily adapt the example to their own use cases.
Merge Readiness
The code is a good starting point for demonstrating the Gen AI SDK's tuning capabilities. However, the missing error handling and the TODO
comment should be addressed before merging. Additionally, consider making the hardcoded values configurable to improve the example's usability. I am unable to directly approve the pull request, and users should have others review and approve this code before merging. Given the medium
severity issues, I recommend addressing them before merging.
# TODO(developer): Update and un-comment below lines | ||
# PROJECT_ID = "your-project-id" |
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.
The PROJECT_ID
should be explicitly set if the environment variable is not found, or the program should exit with an error message. Consider using a default value or raising an exception if the environment variable is not set. This will prevent unexpected behavior if the environment variable is missing.
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
if not PROJECT_ID:
raise ValueError("GOOGLE_CLOUD_PROJECT environment variable must be set.")
tuning_job = client.tunings.get(name=tuning_job.name) | ||
time.sleep(60) |
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.
Consider adding a try-except block to handle potential exceptions during the API call. This will make the example more robust and prevent it from crashing if the API call fails.
try:
tuning_job = client.tunings.get(name=tuning_job.name)
except Exception as e:
print(f"Error getting tuning job: {e}")
break # Exit the loop if there's an error
Here is the summary of possible violations 😱 There is a possible violation for not having product prefix.
The end of the violation section. All the stuff below is FYI purposes only. Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
Add a Gen AI SDK example to create a tuning job.