Skip to content

Draft: Add Firebase Imagen API for Unity #1270

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

jonsimantov
Copy link
Contributor

This commit introduces support for the Firebase Imagen API within the Firebase Unity SDK, enabling image generation capabilities.

New API additions under the Firebase.AI namespace:

  • ImagenModel: Class for interacting with Imagen models.
    • GenerateImagesAsync(prompt, cancellationToken): Generates images inline.
    • GenerateImagesAsync(prompt, gcsUri, cancellationToken): Generates images to a GCS URI.
  • IImagenImage, ImagenInlineImage, ImagenGcsImage: Structs for representing generated images.
    • ImagenInlineImage.AsTexture2D(): Converts inline image data to UnityEngine.Texture2D.
  • ImagenGenerationConfig: Struct for specifying image generation parameters (e.g., number of images, aspect ratio, format).
  • ImagenSafetySettings: Struct for configuring safety filters.
  • ImagenImageFormat: Struct for defining output image format (PNG, JPEG).
  • ImagenAspectRatio: Enum for common image aspect ratios.
  • ImagenGenerationResponse<T>: Struct for the response from image generation calls.

The FirebaseAI class has been extended with:

  • GetImagenModel(modelName, generationConfig, safetySettings, requestOptions): Factory method to obtain an ImagenModel instance.

Integration tests for the Imagen API have been added in firebaseai/testapp/Assets/Firebase/Sample/AI/ImagenTest.cs.

Documentation has been updated in docs/firebaseai/FirebaseAIReadme.md to include usage examples and descriptions for the Imagen API.

Description

Provide details of the change, and generalize the change in the PR title above.


Testing

Describe how you've tested these changes.


Type of Change

Place an x the applicable box:

  • Bug fix. Add the issue # below if applicable.
  • New feature. A non-breaking change which adds functionality.
  • Other, such as a build process or documentation change.

This commit introduces support for the Firebase Imagen API within the Firebase Unity SDK,
enabling image generation capabilities.

New API additions under the `Firebase.AI` namespace:
- `ImagenModel`: Class for interacting with Imagen models.
  - `GenerateImagesAsync(prompt, cancellationToken)`: Generates images inline.
  - `GenerateImagesAsync(prompt, gcsUri, cancellationToken)`: Generates images to a GCS URI.
- `IImagenImage`, `ImagenInlineImage`, `ImagenGcsImage`: Structs for representing generated images.
  - `ImagenInlineImage.AsTexture2D()`: Converts inline image data to `UnityEngine.Texture2D`.
- `ImagenGenerationConfig`: Struct for specifying image generation parameters (e.g., number of images, aspect ratio, format).
- `ImagenSafetySettings`: Struct for configuring safety filters.
- `ImagenImageFormat`: Struct for defining output image format (PNG, JPEG).
- `ImagenAspectRatio`: Enum for common image aspect ratios.
- `ImagenGenerationResponse<T>`: Struct for the response from image generation calls.

The `FirebaseAI` class has been extended with:
- `GetImagenModel(modelName, generationConfig, safetySettings, requestOptions)`: Factory method to obtain an `ImagenModel` instance.

Integration tests for the Imagen API have been added in `firebaseai/testapp/Assets/Firebase/Sample/AI/ImagenTest.cs`.

Documentation has been updated in `docs/firebaseai/FirebaseAIReadme.md` to include usage examples and descriptions for the Imagen API.
Copy link

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

Summary of Changes

Hello @jonsimantov, 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!

This pull request adds comprehensive support for the Firebase Imagen API to the Firebase Unity SDK. It provides developers with the ability to generate images from text prompts directly within their Unity projects, offering flexibility to receive image data inline or store it in Google Cloud Storage. The changes include new API classes, configuration options, response handling, and integration tests, along with updated documentation.

Highlights

  • Image Generation Methods: Added GenerateImagesAsync methods to ImagenModel allowing image generation either inline (returning ImagenInlineImage with byte data) or directly to a specified Google Cloud Storage URI (returning ImagenGcsImage with the URI reference).
  • Unity Integration: Included a helper method ImagenInlineImage.AsTexture2D() to easily convert inline image data into a UnityEngine.Texture2D for use within Unity.
  • FirebaseAI Extension: Extended the main FirebaseAI class with a GetImagenModel factory method to obtain an instance of the new ImagenModel.
  • Testing and Documentation: Added integration tests (ImagenTest.cs) and updated the Firebase AI README (FirebaseAIReadme.md) with documentation and usage examples for the new Imagen API.
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.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@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 pull request introduces support for the Firebase Imagen API in the Unity SDK, adding new classes for model interaction, image representation, and configuration. The changes include API additions under Firebase.AI, integration tests, and documentation updates.

Key areas for attention:

  • API Contract Adherence: Several parts of the code serialize enums to strings or use specific JSON keys for request bodies (e.g., aspect ratio, safety filters, prompt structure, GCS output URI). These must precisely match the backend API specification to prevent errors. Please double-check these against the official Imagen API documentation.
  • Test Configuration: The placeholder model name in ImagenTest.cs needs to be updated to a valid Imagen model, and the GCS bucket path needs to be configured for tests involving GCS output to run successfully.
  • Backend Compatibility: Consider enabling the backend check in FirebaseAI.GetImagenModel if Imagen is strictly VertexAI-only, for a better developer experience.

Overall, the structure and implementation of the new API components look reasonable, pending confirmation of the API contract details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant