-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(genai): Add image generation and code execution examples #4096
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
Conversation
|
Here is the summary of changes. You are about to add 2 region tags.
This comment is generated by snippet-bot.
|
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 @gericdong, 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
Hello! Gemini here, providing a summary of this pull request. This PR, authored by gericdong, introduces new examples for the @google/genai SDK. The primary goal, as indicated by the title and description, is to add quickstart examples demonstrating image generation and code execution capabilities using different Gemini models via the Vertex AI endpoint.
Highlights
- Image Generation Example: Adds a new Node.js example (
imggen-mmflash-with-txt.js) showing how to use thegemini-2.0-flash-expmodel to generate an image based on a text prompt. The example uses streaming and saves the resulting image data to a local file. - Code Execution Example: Adds a new Node.js example (
tools-code-exec-with-txt.js) demonstrating the use of thecodeExecutiontool with thegemini-2.5-flash-preview-05-20model. This example prompts the model to generate and execute code to solve a mathematical problem. - Corresponding Tests: Includes new test files (
imggen-mmflash-with-txt.test.jsandtools-code-exec-with-txt.test.js) using Mocha and Chai to verify the functionality of the new image generation and code execution examples.
Changelog
Click here to see the changelog
- genai/image-generation/imggen-mmflash-with-txt.js
- New file added.
- Contains a Node.js function
generateContentthat uses the@google/genaiSDK to interact with thegemini-2.0-flash-expmodel. - Demonstrates generating both text and image modalities from a single text prompt.
- Includes logic to save the generated image data to a PNG file.
- genai/test/imggen-mmflash-with-txt.test.js
- New file added.
- Adds a Mocha test suite for the
imggen-mmflash-with-txt.jsexample. - Verifies that the
generateContentfunction produces output containing the word 'image'.
- genai/test/tools-code-exec-with-txt.test.js
- New file added.
- Adds a Mocha test suite for the
tools-code-exec-with-txt.jsexample. - Verifies that the
generateContentfunction produces output with a length greater than 0 (indicating a result from code execution).
- genai/tools/tools-code-exec-with-txt.js
- New file added.
- Contains a Node.js function
generateContentthat uses the@google/genaiSDK to interact with thegemini-2.5-flash-preview-05-20model. - Demonstrates enabling and using the
codeExecutiontool. - Prompts the model to calculate the sum of the first 50 prime numbers and logs/returns the execution result.
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.
Code flows like a stream,
Images bloom from a dream,
AI runs the sum.
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
This PR introduces two new examples: one for image generation with streaming (imggen-mmflash-with-txt.js) and another for code execution (tools-code-exec-with-txt.js) using the GenAI SDK. These are valuable additions, especially for users looking for quickstart examples.
The code is generally clear and demonstrates the core functionalities well. I've focused my review on improving the robustness, error handling, and testability of the new image generation example. My review comments are based on general JavaScript best practices for code clarity, robustness, and maintainability, as no specific style guide was provided for this repository.
Summary of Findings
- Copyright Year: The copyright year in the new files (
genai/image-generation/imggen-mmflash-with-txt.js,genai/tools/tools-code-exec-with-txt.js) is set to 2025. This should likely be updated to the current year if it's a typo. (Severity: low, not commented inline due to review settings) - Logging Practice: The examples use
console.debugfor logging. While acceptable for simple examples, consider advising users or using a more structured logger in production code or more complex samples for better log management and filtering. (Severity: low, not commented inline due to review settings) - Test Assertion Specificity (Code Execution): In
genai/test/tools-code-exec-with-txt.test.js(line 26), the assertionassert(output.length > 0)is a good basic check. For more robustness, you could consider if more specific assertions can be made about thecodeExecutionResult(e.g., type checking if it's expected to be a number, or matching a pattern if it's a string with a known format), depending on the predictability of the LLM's output for the given prompt. (Severity: low, not commented inline due to review settings)
Merge Readiness
The PR is a good step towards providing useful examples for image generation and code execution. However, I recommend addressing the medium severity comments related to the image generation example's return value, error handling, and its test validation before merging. These changes will significantly improve the reliability and usability of the example.
As an AI reviewer, I am not authorized to approve this pull request. Please ensure it undergoes further review and approval according to your team's established processes.
Add image generation and code execution examples.
For Quickstart.