Skip to content

Conversation

@calren
Copy link
Collaborator

@calren calren commented May 22, 2025

Tested: Ran app on Pixel 9 and tried all Firebase-related samples in catalog

Prompt used with Jules:

can you refactor this repository to use the latest version if Firebase AI Logic SDK instead of the current vertex-ai-in-firebase SDK

this is the pull request you can reference to do this https://github.com/android/androidify/pull/9.

you should look in the following samples: gemini-chatbot, gemini-multimodal, gemini-video-summarization, imagen, magic-selfie

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.
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 @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-vertexai SDK to the new firebase-ai SDK across multiple AI samples.
  • Dependency Updates: The Firebase Bill of Materials (BOM) version has been updated, and the firebase-vertexai dependency has been replaced with firebase-ai in the shared libs.versions.toml file and individual sample build.gradle.kts files.
  • Code Refactoring: Kotlin source files, primarily ViewModels in the affected samples, have been updated to change import statements from com.google.firebase.vertexai.* to com.google.firebase.ai.* and modify the SDK initialization call from Firebase.vertexAI... to Firebase.ai(backend = GenerativeBackend.vertexAI())....

Changelog

Click here to see the changelog
  • ai-catalog/gradle/libs.versions.toml
    • Updated firebaseBom version from 33.12.0 to 33.14.0.
    • Replaced the firebase-vertexai library definition with firebase-ai.
  • ai-catalog/samples/gemini-chatbot/build.gradle.kts
    • Replaced the implementation(libs.firebase.vertexai) dependency with implementation(libs.firebase.ai).
  • ai-catalog/samples/gemini-chatbot/src/main/java/com/android/ai/samples/geminichatbot/GeminiChatbotViewModel.kt
    • Changed import statements from com.google.firebase.vertexai.* to com.google.firebase.ai.* (lines 23-28).
    • Added import for com.google.firebase.ai.type.GenerativeBackend (line 29).
    • Changed SDK initialization from Firebase.vertexAI.generativeModel to Firebase.ai(backend = GenerativeBackend.vertexAI()).generativeModel (line 41).
  • ai-catalog/samples/gemini-multimodal/build.gradle.kts
    • Replaced the implementation(libs.firebase.vertexai) dependency with implementation(libs.firebase.ai).
  • ai-catalog/samples/gemini-multimodal/src/main/java/com/android/ai/samples/geminimultimodal/GeminiMultimodalViewModel.kt
    • Changed import statements from com.google.firebase.vertexai.* to com.google.firebase.ai.* (lines 24-29).
    • Added import for com.google.firebase.ai.type.GenerativeBackend (line 30).
    • Changed SDK initialization from Firebase.vertexAI.generativeModel to Firebase.ai(backend = GenerativeBackend.vertexAI()).generativeModel (line 45).
  • ai-catalog/samples/gemini-video-summarization/build.gradle.kts
    • Replaced the implementation(libs.firebase.vertexai) dependency with implementation(libs.firebase.ai).
  • 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.* to com.google.firebase.ai.* (lines 25-26).
    • Added import for com.google.firebase.ai.type.GenerativeBackend (line 27).
    • Changed SDK initialization from Firebase.vertexAI.generativeModel to Firebase.ai(backend = GenerativeBackend.vertexAI()).generativeModel (line 54).
  • ai-catalog/samples/imagen/build.gradle.kts
    • Replaced the implementation(libs.firebase.vertexai) dependency with implementation(libs.firebase.ai).
  • ai-catalog/samples/imagen/src/main/java/com/android/ai/samples/imagen/ImagenViewModel.kt
    • Changed import statements from com.google.firebase.vertexai.* to com.google.firebase.ai.* (lines 26-31).
    • Added import for com.google.firebase.ai.type.GenerativeBackend (line 27).
    • Changed SDK initialization from Firebase.vertexAI.imagenModel to Firebase.ai(backend = GenerativeBackend.vertexAI()).imagenModel (line 45).
  • ai-catalog/samples/magic-selfie/build.gradle.kts
    • Replaced the implementation(libs.firebase.vertexai) dependency with implementation(libs.firebase.ai).
  • ai-catalog/samples/magic-selfie/src/main/java/com/android/ai/samples/magicselfie/MagicSelfieViewModel.kt
    • Changed import statements from com.google.firebase.vertexai.* to com.google.firebase.ai.* (lines 28-33).
    • Added import for com.google.firebase.ai.type.GenerativeBackend (line 29).
    • Changed SDK initialization from Firebase.vertexAI.imagenModel to Firebase.ai(backend = GenerativeBackend.vertexAI()).imagenModel (line 52).
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

  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 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-vertexai with firebase-ai has 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 firebaseBom version has been appropriately updated in gradle/libs.versions.toml (from 33.12.0 to 33.14.0), and the new firebase-ai dependency 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, or critical severity 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.

Copy link
Collaborator

@lethargicpanda lethargicpanda left a 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(
Copy link
Collaborator

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(
Copy link
Collaborator

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")
Copy link
Collaborator

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(
Copy link
Collaborator

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(
Copy link
Collaborator

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.

@calren
Copy link
Collaborator Author

calren commented Jun 3, 2025

closing in favor of #41

@calren calren closed this Jun 3, 2025
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