Skip to content

Conversation

@lethargicpanda
Copy link
Collaborator

Migrate to Firebase AI Logic and update to Imagen 4

Migrate to Firebase AI Logic and update to Imagen 4
@lethargicpanda lethargicpanda requested a review from calren June 3, 2025 17:47
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 @lethargicpanda, 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 migrates the project to use Firebase AI Logic and updates the Imagen library to version 4.0. The primary changes involve updating dependencies in build.gradle.kts files and replacing firebase-vertexai with firebase-ai. Additionally, the code is updated to use the new Firebase AI API for accessing generative models.

Highlights

  • Firebase AI Logic Migration: The project is migrated from using the firebase-vertexai library to firebase-ai, reflecting the shift to Firebase AI Logic.
  • Imagen Library Update: The Imagen library is updated to version 4.0, specifically imagen-4.0-generate-preview-05-20, to leverage the latest features and improvements.
  • API Usage Update: The code is updated to use the new Firebase AI API for accessing generative models, replacing the previous Vertex AI API calls.

Changelog

Click here to see the changelog
  • ai-catalog/README.md
    • Updated Firebase setup documentation links to point to the Firebase AI Logic documentation instead of Vertex AI documentation.
  • ai-catalog/app/build.gradle.kts
    • Replaced implementation(libs.firebase.vertexai) with implementation(libs.firebase.ai) to use the new Firebase AI library.
  • ai-catalog/gradle/libs.versions.toml
    • Updated firebaseBom version from 33.12.0 to 33.14.0.
    • Replaced firebase-vertexai with firebase-ai in the libraries section.
  • ai-catalog/samples/gemini-chatbot/build.gradle.kts
    • Replaced implementation(libs.firebase.vertexai) with implementation(libs.firebase.ai).
  • ai-catalog/samples/gemini-chatbot/src/main/java/com/android/ai/samples/geminichatbot/GeminiChatbotViewModel.kt
    • Replaced imports from com.google.firebase.vertexai.type with imports from com.google.firebase.ai.type.
    • Updated the generativeModel initialization to use Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel() instead of Firebase.vertexAI.generativeModel().
    • Updated systemInstruction content to use text() function.
  • ai-catalog/samples/gemini-multimodal/build.gradle.kts
    • Replaced implementation(libs.firebase.vertexai) with implementation(libs.firebase.ai).
  • ai-catalog/samples/gemini-multimodal/src/main/java/com/android/ai/samples/geminimultimodal/GeminiMultimodalViewModel.kt
    • Replaced imports from com.google.firebase.vertexai.type with imports from com.google.firebase.ai.type.
    • Updated the generativeModel initialization to use Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel() instead of Firebase.vertexAI.generativeModel().
  • ai-catalog/samples/gemini-video-summarization/build.gradle.kts
    • Replaced implementation(libs.firebase.vertexai) with implementation(libs.firebase.ai).
  • ai-catalog/samples/gemini-video-summarization/src/main/java/com/android/ai/samples/geminivideosummary/viewmodel/VideoSummarizationViewModel.kt
    • Replaced imports from com.google.firebase.vertexai.type with imports from com.google.firebase.ai.type.
    • Updated the generativeModel initialization to use Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel() instead of Firebase.vertexAI.generativeModel().
  • ai-catalog/samples/genai-image-description/src/main/java/com/android/ai/samples/genai_image_description/GenAIImageDescriptionViewModel.kt
    • Removed unnecessary import of android.graphics.Bitmap.
    • Moved import com.android.ai.samples.geminimultimodal.R to the top of the imports.
  • ai-catalog/samples/imagen/build.gradle.kts
    • Replaced implementation(libs.firebase.vertexai) with implementation(libs.firebase.ai).
  • ai-catalog/samples/imagen/src/main/java/com/android/ai/samples/imagen/ImagenViewModel.kt
    • Replaced imports from com.google.firebase.vertexai.type with imports from com.google.firebase.ai.type.
    • Updated the imagenModel initialization to use Firebase.ai(backend = GenerativeBackend.vertexAI()).imagenModel() instead of Firebase.vertexAI.imagenModel().
    • Updated the modelName to imagen-4.0-generate-preview-05-20 and removed addWatermark = true.
  • ai-catalog/samples/magic-selfie/build.gradle.kts
    • Replaced implementation(libs.firebase.vertexai) with implementation(libs.firebase.ai).
  • ai-catalog/samples/magic-selfie/src/main/java/com/android/ai/samples/magicselfie/MagicSelfieViewModel.kt
    • Replaced imports from com.google.firebase.vertexai.type with imports from com.google.firebase.ai.type.
    • Updated the imagenModel initialization to use Firebase.ai(backend = GenerativeBackend.vertexAI()).imagenModel() instead of Firebase.vertexAI.imagenModel().
    • Updated the modelName to imagen-4.0-generate-preview-05-20 and removed addWatermark = true.
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.


The models evolve,
New APIs to resolve,
Firebase AI,
A better way,
Code changes now absolve.

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

The pull request migrates the project to use Firebase AI Logic and updates the Imagen library to version 4. The changes involve updating dependencies, modifying code to use the new Firebase AI APIs, and updating the Imagen model name. Overall, the changes seem correct and necessary for the migration. However, there are a few areas that could be improved.

Summary of Findings

  • Firebase AI Logic Migration: The project is migrated to use Firebase AI Logic, replacing the previous Vertex AI implementation. This involves updating dependencies and modifying code to use the new Firebase AI APIs.
  • Imagen 4 Update: The Imagen library is updated to version 4, which includes updating the model name and removing the addWatermark parameter.
  • README Updates: The README file is updated to reflect the Firebase AI Logic migration and provide instructions for setting up the project with Firebase.

Merge Readiness

The pull request appears to be on the right track for migrating to Firebase AI Logic and updating to Imagen 4. However, it's crucial to verify the compatibility of the new dependencies, ensure the correct model name is used, and confirm that the removal of the watermark does not violate any policies. I am unable to approve the pull request in any circumstance, and users should have others review and approve this code before merging. I recommend addressing the comments before merging.

implementation(libs.hilt.navigation.compose)
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.vertexai)
implementation(libs.firebase.ai)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The dependency libs.firebase.ai is added, replacing libs.firebase.vertexai. This is the correct change for migrating to Firebase AI Logic. Ensure that all necessary configurations and initializations related to the new dependency are also handled correctly in the code.

coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coilCompose" }
firebase-bom = { module = "com.google.firebase:firebase-bom", version.ref = "firebaseBom" }
firebase-vertexai = { group = "com.google.firebase", name = "firebase-vertexai" }
firebase-ai = { group = "com.google.firebase", name = "firebase-ai" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The dependency firebase-ai is added, replacing firebase-vertexai. This is the correct change for migrating to Firebase AI Logic. Ensure that the version is compatible with the rest of the Firebase dependencies.

implementation(libs.androidx.material.icons.extended)
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.vertexai)
implementation(libs.firebase.ai)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The dependency libs.firebase.ai is added, replacing libs.firebase.vertexai. This is the correct change for migrating to Firebase AI Logic. Ensure that all necessary configurations and initializations related to the new dependency are also handled correctly in the code.

implementation(libs.androidx.material.icons.extended)
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.vertexai)
implementation(libs.firebase.ai)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The dependency libs.firebase.ai is added, replacing libs.firebase.vertexai. This is the correct change for migrating to Firebase AI Logic. Ensure that all necessary configurations and initializations related to the new dependency are also handled correctly in the code.

ksp(libs.hilt.compiler)
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.vertexai)
implementation(libs.firebase.ai)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The dependency libs.firebase.ai is added, replacing libs.firebase.vertexai. This is the correct change for migrating to Firebase AI Logic. Ensure that all necessary configurations and initializations related to the new dependency are also handled correctly in the code.

implementation(libs.androidx.material.icons.extended)
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.vertexai)
implementation(libs.firebase.ai)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The dependency libs.firebase.ai is added, replacing libs.firebase.vertexai. This is the correct change for migrating to Firebase AI Logic. Ensure that all necessary configurations and initializations related to the new dependency are also handled correctly in the code.

Comment on lines +52 to +53
private val imagenModel = Firebase.ai(backend = GenerativeBackend.vertexAI()).imagenModel(
modelName = "imagen-4.0-generate-preview-05-20",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The model name is updated to imagen-4.0-generate-preview-05-20. This is the correct change for updating to Imagen 4. Ensure that this model name is valid and available in the Firebase AI Logic environment.


> **Requires Firebase setup** the samples relying on Google Cloud models (Gemini Pro, Gemini Flash, etc...)
> require setting up a Firebase project and connecting the app to Firebase (read more [here](https://firebase.google.com/docs/vertex-ai/get-started?platform=android#set-up-firebase)).
> require setting up a Firebase project and connecting the app to Firebase (read more [here](https://firebase.google.com/docs/ai-logic/get-started?platform=android&api=dev#set-up-firebase)).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The link in the README is updated to point to the Firebase AI Logic documentation, which is great. However, consider adding a brief explanation of what Firebase AI Logic is and why it's being used in this project. This would provide more context for users who are new to the project.

2. Open the whole project in Android Studio.
3. Set up a Firebase project and connect your app to Firebase by adding your Firebase configuration
file (google-services.json) to the app. Read more [here](https://firebase.google.com/docs/vertex-ai/get-started?platform=android#set-up-firebase).
file (google-services.json) to the app. Read more [here](https://firebase.google.com/docs/ai-logic/get-started?platform=android&api=dev#set-up-firebase).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Same comment as above, consider adding a brief explanation of what Firebase AI Logic is and why it's being used in this project.

generationConfig = ImagenGenerationConfig(
numberOfImages = 1,
aspectRatio = ImagenAspectRatio.PORTRAIT_3x4,
imageFormat = ImagenImageFormat.jpeg(compressionQuality = 75),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The addWatermark parameter is removed from the ImagenGenerationConfig. This is likely due to changes in the Imagen 4 API. Verify that the removal of the watermark does not violate any usage policies or requirements.

@lethargicpanda lethargicpanda merged commit 2e0c14c into main Jun 3, 2025
1 check passed
@lethargicpanda lethargicpanda deleted the ai-logic-imagen branch July 15, 2025 07:38
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.

2 participants