-
Notifications
You must be signed in to change notification settings - Fork 145
Firebase AI Logic and Imagen update #41
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
Migrate to Firebase AI Logic and update to Imagen 4
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 @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-vertexailibrary tofirebase-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)withimplementation(libs.firebase.ai)to use the new Firebase AI library.
- Replaced
- ai-catalog/gradle/libs.versions.toml
- Updated
firebaseBomversion from33.12.0to33.14.0. - Replaced
firebase-vertexaiwithfirebase-aiin the libraries section.
- Updated
- ai-catalog/samples/gemini-chatbot/build.gradle.kts
- Replaced
implementation(libs.firebase.vertexai)withimplementation(libs.firebase.ai).
- Replaced
- ai-catalog/samples/gemini-chatbot/src/main/java/com/android/ai/samples/geminichatbot/GeminiChatbotViewModel.kt
- Replaced imports from
com.google.firebase.vertexai.typewith imports fromcom.google.firebase.ai.type. - Updated the
generativeModelinitialization to useFirebase.ai(backend = GenerativeBackend.googleAI()).generativeModel()instead ofFirebase.vertexAI.generativeModel(). - Updated
systemInstructioncontent to usetext()function.
- Replaced imports from
- ai-catalog/samples/gemini-multimodal/build.gradle.kts
- Replaced
implementation(libs.firebase.vertexai)withimplementation(libs.firebase.ai).
- Replaced
- ai-catalog/samples/gemini-multimodal/src/main/java/com/android/ai/samples/geminimultimodal/GeminiMultimodalViewModel.kt
- Replaced imports from
com.google.firebase.vertexai.typewith imports fromcom.google.firebase.ai.type. - Updated the
generativeModelinitialization to useFirebase.ai(backend = GenerativeBackend.googleAI()).generativeModel()instead ofFirebase.vertexAI.generativeModel().
- Replaced imports from
- ai-catalog/samples/gemini-video-summarization/build.gradle.kts
- Replaced
implementation(libs.firebase.vertexai)withimplementation(libs.firebase.ai).
- Replaced
- ai-catalog/samples/gemini-video-summarization/src/main/java/com/android/ai/samples/geminivideosummary/viewmodel/VideoSummarizationViewModel.kt
- Replaced imports from
com.google.firebase.vertexai.typewith imports fromcom.google.firebase.ai.type. - Updated the
generativeModelinitialization to useFirebase.ai(backend = GenerativeBackend.googleAI()).generativeModel()instead ofFirebase.vertexAI.generativeModel().
- Replaced imports from
- 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.Rto the top of the imports.
- Removed unnecessary import of
- ai-catalog/samples/imagen/build.gradle.kts
- Replaced
implementation(libs.firebase.vertexai)withimplementation(libs.firebase.ai).
- Replaced
- ai-catalog/samples/imagen/src/main/java/com/android/ai/samples/imagen/ImagenViewModel.kt
- Replaced imports from
com.google.firebase.vertexai.typewith imports fromcom.google.firebase.ai.type. - Updated the
imagenModelinitialization to useFirebase.ai(backend = GenerativeBackend.vertexAI()).imagenModel()instead ofFirebase.vertexAI.imagenModel(). - Updated the
modelNametoimagen-4.0-generate-preview-05-20and removedaddWatermark = true.
- Replaced imports from
- ai-catalog/samples/magic-selfie/build.gradle.kts
- Replaced
implementation(libs.firebase.vertexai)withimplementation(libs.firebase.ai).
- Replaced
- ai-catalog/samples/magic-selfie/src/main/java/com/android/ai/samples/magicselfie/MagicSelfieViewModel.kt
- Replaced imports from
com.google.firebase.vertexai.typewith imports fromcom.google.firebase.ai.type. - Updated the
imagenModelinitialization to useFirebase.ai(backend = GenerativeBackend.vertexAI()).imagenModel()instead ofFirebase.vertexAI.imagenModel(). - Updated the
modelNametoimagen-4.0-generate-preview-05-20and removedaddWatermark = true.
- Replaced imports from
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
-
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 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
addWatermarkparameter. - 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) |
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.
| 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" } |
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.
| implementation(libs.androidx.material.icons.extended) | ||
| implementation(platform(libs.firebase.bom)) | ||
| implementation(libs.firebase.vertexai) | ||
| implementation(libs.firebase.ai) |
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.
| implementation(libs.androidx.material.icons.extended) | ||
| implementation(platform(libs.firebase.bom)) | ||
| implementation(libs.firebase.vertexai) | ||
| implementation(libs.firebase.ai) |
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.
| ksp(libs.hilt.compiler) | ||
| implementation(platform(libs.firebase.bom)) | ||
| implementation(libs.firebase.vertexai) | ||
| implementation(libs.firebase.ai) |
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.
| implementation(libs.androidx.material.icons.extended) | ||
| implementation(platform(libs.firebase.bom)) | ||
| implementation(libs.firebase.vertexai) | ||
| implementation(libs.firebase.ai) |
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.
| private val imagenModel = Firebase.ai(backend = GenerativeBackend.vertexAI()).imagenModel( | ||
| modelName = "imagen-4.0-generate-preview-05-20", |
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.
|
|
||
| > **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)). |
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.
| 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). |
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.
| generationConfig = ImagenGenerationConfig( | ||
| numberOfImages = 1, | ||
| aspectRatio = ImagenAspectRatio.PORTRAIT_3x4, | ||
| imageFormat = ImagenImageFormat.jpeg(compressionQuality = 75), |
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.
Migrate to Firebase AI Logic and update to Imagen 4