Skip to content

Conversation

@gericdong
Copy link
Contributor

Add image generation and code execution examples.

For Quickstart.

@gericdong gericdong requested review from a team as code owners May 21, 2025 19:07
@snippet-bot
Copy link

snippet-bot bot commented May 21, 2025

Here is the summary of changes.

You are about to add 2 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label May 21, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 the gemini-2.0-flash-exp model 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 the codeExecution tool with the gemini-2.5-flash-preview-05-20 model. 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.js and tools-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 generateContent that uses the @google/genai SDK to interact with the gemini-2.0-flash-exp model.
    • 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.js example.
    • Verifies that the generateContent function 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.js example.
    • Verifies that the generateContent function 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 generateContent that uses the @google/genai SDK to interact with the gemini-2.5-flash-preview-05-20 model.
    • Demonstrates enabling and using the codeExecution tool.
    • 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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.debug for 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 assertion assert(output.length > 0) is a good basic check. For more robustness, you could consider if more specific assertions can be made about the codeExecutionResult (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.

@msampathkumar msampathkumar merged commit 2e46a66 into main May 22, 2025
18 checks passed
@msampathkumar msampathkumar deleted the quickstart-0521 branch May 22, 2025 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants