-
Notifications
You must be signed in to change notification settings - Fork 140
[Jules] Refactor to use Firebase AI Logic SDK #33
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
I've replaced the `firebase-vertexai` SDK with the new `firebase-ai` (Firebase AI Logic SDK) across multiple samples.
Key changes include:
- Updated `gradle/libs.versions.toml` to use the new `firebase-ai` dependency and updated the Firebase BOM.
- Modified `build.gradle.kts` files for the affected samples (`gemini-chatbot`, `gemini-multimodal`, `gemini-video-summarization`, `imagen`, `magic-selfie`) to implement `libs.firebase.ai`.
- Updated Kotlin source files (primarily ViewModels) in these samples to:
- Change import statements from `com.google.firebase.vertexai.*` to `com.google.firebase.ai.*`.
- Update SDK initialization from `Firebase.vertexAI...` to `Firebase.ai(backend = GenerativeBackend.vertexAI())...`.
- Ensured correct imports for `Firebase`, `Firebase.ai`, and `GenerativeBackend`.
This change aligns the samples with the latest Firebase AI Logic SDK, as demonstrated in the reference PR android/androidify#9.
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 @calren, 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 or gemini-code-assist here, providing a summary of this pull request. This PR aims to refactor several AI samples within the ai-catalog to migrate from the older firebase-vertexai SDK to the new firebase-ai (Firebase AI Logic SDK). This change involves updating dependencies, modifying build configurations, and adjusting the SDK initialization and import statements in the relevant Kotlin source files. The goal is to align these samples with the latest recommended Firebase SDK for AI logic, as demonstrated in a reference PR.
Highlights
- SDK Migration: The core change is the migration from the
firebase-vertexaiSDK to the newfirebase-aiSDK across multiple AI samples. - Dependency Updates: The Firebase Bill of Materials (BOM) version has been updated, and the
firebase-vertexaidependency has been replaced withfirebase-aiin the sharedlibs.versions.tomlfile and individual samplebuild.gradle.ktsfiles. - Code Refactoring: Kotlin source files, primarily ViewModels in the affected samples, have been updated to change import statements from
com.google.firebase.vertexai.*tocom.google.firebase.ai.*and modify the SDK initialization call fromFirebase.vertexAI...toFirebase.ai(backend = GenerativeBackend.vertexAI())....
Changelog
Click here to see the changelog
- ai-catalog/gradle/libs.versions.toml
- Updated
firebaseBomversion from33.12.0to33.14.0. - Replaced the
firebase-vertexailibrary definition withfirebase-ai.
- Updated
- ai-catalog/samples/gemini-chatbot/build.gradle.kts
- Replaced the
implementation(libs.firebase.vertexai)dependency withimplementation(libs.firebase.ai).
- Replaced the
- ai-catalog/samples/gemini-chatbot/src/main/java/com/android/ai/samples/geminichatbot/GeminiChatbotViewModel.kt
- Changed import statements from
com.google.firebase.vertexai.*tocom.google.firebase.ai.*(lines 23-28). - Added import for
com.google.firebase.ai.type.GenerativeBackend(line 29). - Changed SDK initialization from
Firebase.vertexAI.generativeModeltoFirebase.ai(backend = GenerativeBackend.vertexAI()).generativeModel(line 41).
- Changed import statements from
- ai-catalog/samples/gemini-multimodal/build.gradle.kts
- Replaced the
implementation(libs.firebase.vertexai)dependency withimplementation(libs.firebase.ai).
- Replaced the
- ai-catalog/samples/gemini-multimodal/src/main/java/com/android/ai/samples/geminimultimodal/GeminiMultimodalViewModel.kt
- Changed import statements from
com.google.firebase.vertexai.*tocom.google.firebase.ai.*(lines 24-29). - Added import for
com.google.firebase.ai.type.GenerativeBackend(line 30). - Changed SDK initialization from
Firebase.vertexAI.generativeModeltoFirebase.ai(backend = GenerativeBackend.vertexAI()).generativeModel(line 45).
- Changed import statements from
- ai-catalog/samples/gemini-video-summarization/build.gradle.kts
- Replaced the
implementation(libs.firebase.vertexai)dependency withimplementation(libs.firebase.ai).
- Replaced the
- ai-catalog/samples/gemini-video-summarization/src/main/java/com/android/ai/samples/geminivideosummary/viewmodel/VideoSummarizationViewModel.kt
- Changed import statements from
com.google.firebase.vertexai.*tocom.google.firebase.ai.*(lines 25-26). - Added import for
com.google.firebase.ai.type.GenerativeBackend(line 27). - Changed SDK initialization from
Firebase.vertexAI.generativeModeltoFirebase.ai(backend = GenerativeBackend.vertexAI()).generativeModel(line 54).
- Changed import statements from
- ai-catalog/samples/imagen/build.gradle.kts
- Replaced the
implementation(libs.firebase.vertexai)dependency withimplementation(libs.firebase.ai).
- Replaced the
- ai-catalog/samples/imagen/src/main/java/com/android/ai/samples/imagen/ImagenViewModel.kt
- Changed import statements from
com.google.firebase.vertexai.*tocom.google.firebase.ai.*(lines 26-31). - Added import for
com.google.firebase.ai.type.GenerativeBackend(line 27). - Changed SDK initialization from
Firebase.vertexAI.imagenModeltoFirebase.ai(backend = GenerativeBackend.vertexAI()).imagenModel(line 45).
- Changed import statements from
- ai-catalog/samples/magic-selfie/build.gradle.kts
- Replaced the
implementation(libs.firebase.vertexai)dependency withimplementation(libs.firebase.ai).
- Replaced the
- ai-catalog/samples/magic-selfie/src/main/java/com/android/ai/samples/magicselfie/MagicSelfieViewModel.kt
- Changed import statements from
com.google.firebase.vertexai.*tocom.google.firebase.ai.*(lines 28-33). - Added import for
com.google.firebase.ai.type.GenerativeBackend(line 29). - Changed SDK initialization from
Firebase.vertexAI.imagenModeltoFirebase.ai(backend = GenerativeBackend.vertexAI()).imagenModel(line 52).
- Changed import statements 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.
New SDK arrives,
Old imports fade away now,
AI logic flows.
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 pull request effectively refactors multiple Android sample projects to utilize the new firebase-ai (Firebase AI Logic SDK), replacing the older firebase-vertexai SDK. The changes are clear, consistent across all affected modules, and align well with the PR description.
Well done on this systematic update! The migration to the latest Firebase AI Logic SDK is an important step for keeping these samples current.
Summary of Findings
- Successful SDK Migration: The core goal of replacing
firebase-vertexaiwithfirebase-aihas been successfully achieved. The new SDK initialization pattern,Firebase.ai(backend = GenerativeBackend.vertexAI())..., and the corresponding import changes for types and functions (e.g.,com.google.firebase.ai.ai,com.google.firebase.ai.type.*) are correctly implemented in all relevant ViewModel files. - Dependency Management: The
firebaseBomversion has been appropriately updated ingradle/libs.versions.toml(from33.12.0to33.14.0), and the newfirebase-aidependency has been correctly defined and implemented in the project and module-level Gradle files. - Consistency and Clarity: The changes are applied consistently across all modified samples (
gemini-chatbot,gemini-multimodal,gemini-video-summarization,imagen,magic-selfie), making the refactoring easy to understand and verify. - Adherence to Review Settings: A thorough review of the changes was conducted. No issues of
medium,high, orcriticalseverity were identified. Consequently, no specific line-by-line code comments are provided, in accordance with the repository's review settings for this pull request.
Merge Readiness
The pull request appears to be in good shape and implements the intended SDK migration effectively. Given that no significant issues were found during this review, the changes should be ready for merging after any standard automated checks and further reviews are complete. As an AI reviewer, I am not authorized to approve pull requests, so please ensure it undergoes the necessary human review process.
lethargicpanda
left a comment
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.
It did 80% of the work right, but tweaking the prompt can probably improve this... We should use googleAI() as an API provider and update the Readme.
I would suggest to close this CL for now.
|
|
||
| private val generativeModel by lazy { | ||
| Firebase.vertexAI.generativeModel( | ||
| Firebase.ai(backend = GenerativeBackend.vertexAI()).generativeModel( |
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.
we should use googleAI() as an API provider.
|
|
||
| private val generativeModel by lazy { | ||
| Firebase.vertexAI.generativeModel( | ||
| Firebase.ai(backend = GenerativeBackend.vertexAI()).generativeModel( |
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.
we should use googleAI() as an API provider.
|
|
||
| try { | ||
| val generativeModel = Firebase.vertexAI.generativeModel("gemini-2.0-flash") | ||
| val generativeModel = Firebase.ai(backend = GenerativeBackend.vertexAI()).generativeModel("gemini-2.0-flash") |
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.
we should use googleAI() as an API provider.
|
|
||
| @OptIn(PublicPreviewAPI::class) | ||
| private val imagenModel = Firebase.vertexAI.imagenModel( | ||
| private val imagenModel = Firebase.ai(backend = GenerativeBackend.vertexAI()).imagenModel( |
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.
googleAI() as an API provider.
| val progress: LiveData<String?> = _progress | ||
|
|
||
| private val imagenModel = Firebase.vertexAI.imagenModel( | ||
| private val imagenModel = Firebase.ai(backend = GenerativeBackend.vertexAI()).imagenModel( |
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.
googleAI() as an API provider.
|
closing in favor of #41 |
Tested: Ran app on Pixel 9 and tried all Firebase-related samples in catalog
Prompt used with Jules: