Skip to content

Commit 37db915

Browse files
authored
refactor(ai-logic): use vertexAI() for samples that use Cloud Storage (#2675)
1 parent 3afd4de commit 37db915

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

firebase-ai/app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id("com.android.application")
33
id("org.jetbrains.kotlin.android")
44
id("org.jetbrains.kotlin.plugin.compose")
5-
kotlin("plugin.serialization") version "2.1.20"
5+
kotlin("plugin.serialization") version "2.1.21"
66
id("com.google.gms.google-services")
77
}
88

firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/FirebaseAISamples.kt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.google.firebase.quickstart.ai
22

3+
import com.google.firebase.ai.type.GenerativeBackend
34
import com.google.firebase.ai.type.ResponseModality
45
import com.google.firebase.ai.type.content
56
import com.google.firebase.ai.type.generationConfig
@@ -86,10 +87,11 @@ val FIREBASE_AI_SAMPLES = listOf(
8687
}
8788
),
8889
Sample(
89-
title = "Translation from audio",
90-
description = "Translate an audio file",
90+
title = "Translation from audio (Vertex AI)",
91+
description = "Translate an audio file stored in Cloud Storage",
9192
navRoute = "chat",
9293
categories = listOf(Category.AUDIO),
94+
backend = GenerativeBackend.vertexAI(),
9395
initialPrompt = content {
9496
fileData(
9597
"https://storage.googleapis.com/cloud-samples-data/generative-ai/audio/" +
@@ -100,10 +102,11 @@ val FIREBASE_AI_SAMPLES = listOf(
100102
}
101103
),
102104
Sample(
103-
title = "Blog post creator",
104-
description = "Create a blog post from an image file.",
105+
title = "Blog post creator (Vertex AI)",
106+
description = "Create a blog post from an image file stored in Cloud Storage.",
105107
navRoute = "chat",
106108
categories = listOf(Category.IMAGE),
109+
backend = GenerativeBackend.vertexAI(),
107110
initialPrompt = content {
108111
fileData(
109112
"https://storage.googleapis.com/cloud-samples-data/generative-ai/image/meal-prep.jpeg",
@@ -145,10 +148,12 @@ val FIREBASE_AI_SAMPLES = listOf(
145148
}
146149
),
147150
Sample(
148-
title = "Document comparison",
149-
description = "Compare the contents of 2 documents",
151+
title = "Document comparison (Vertex AI)",
152+
description = "Compare the contents of 2 documents." +
153+
" Only supported by the Vertex AI Gemini API because the documents are stored in Cloud Storage",
150154
navRoute = "chat",
151155
categories = listOf(Category.DOCUMENT),
156+
backend = GenerativeBackend.vertexAI(),
152157
initialPrompt = content {
153158
fileData(
154159
"https://storage.googleapis.com/cloud-samples-data/generative-ai/pdf/form_1040_2013.pdf",
@@ -165,10 +170,11 @@ val FIREBASE_AI_SAMPLES = listOf(
165170
}
166171
),
167172
Sample(
168-
title = "Hashtags for a video",
169-
description = "Generate hashtags for a video ad",
173+
title = "Hashtags for a video (Vertex AI)",
174+
description = "Generate hashtags for a video ad stored in Cloud Storage",
170175
navRoute = "chat",
171176
categories = listOf(Category.VIDEO),
177+
backend = GenerativeBackend.vertexAI(),
172178
initialPrompt = content {
173179
fileData(
174180
"https://storage.googleapis.com/cloud-samples-data/generative-ai/video/google_home_celebrity_ad.mp4",

firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ChatViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class ChatViewModel(
5757

5858
init {
5959
val generativeModel = Firebase.ai(
60-
backend = GenerativeBackend.googleAI()
60+
backend = sample.backend // GenerativeBackend.googleAI() by default
6161
).generativeModel(
6262
modelName = sample.modelName ?: "gemini-2.0-flash",
6363
systemInstruction = sample.systemInstructions,

firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/ui/navigation/Sample.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.google.firebase.quickstart.ai.ui.navigation
22

33
import com.google.firebase.ai.type.Content
44
import com.google.firebase.ai.type.GenerationConfig
5+
import com.google.firebase.ai.type.GenerativeBackend
56
import java.util.UUID
67

78
enum class Category(
@@ -22,6 +23,7 @@ data class Sample(
2223
val categories: List<Category>,
2324
// Optional parameters
2425
val modelName: String? = null,
26+
val backend: GenerativeBackend = GenerativeBackend.googleAI(),
2527
val initialPrompt: Content? = null,
2628
val systemInstructions: Content? = null,
2729
val generationConfig: GenerationConfig? = null,

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
agp = "8.10.1"
33
coilCompose = "2.7.0"
44
firebaseBom = "33.15.0"
5-
kotlin = "2.1.20"
5+
kotlin = "2.1.21"
66
coreKtx = "1.16.0"
77
junit = "4.13.2"
88
junitVersion = "1.2.1"

0 commit comments

Comments
 (0)