Skip to content

Commit 2691dc7

Browse files
authored
feat(ai-logic): add samples demonstrating Gemini 3.1 Flash-Lite preview (firebase#2769)
This should add a new translation sample that uses Gemini 3.1 Flash-Lite preview Also updates the audio summarization sample to use Gemini 3.1 Flash-Lite instead of Gemini 2.5 Flash.
1 parent 69aa3c3 commit 2691dc7

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AudioSummarizationViewModel : ChatViewModel() {
2828
val generativeModel = Firebase.ai(
2929
backend = GenerativeBackend.googleAI()
3030
).generativeModel(
31-
modelName = "gemini-2.5-flash"
31+
modelName = "gemini-3.1-flash-lite-preview"
3232
)
3333
chat = generativeModel.startChat(
3434
listOf(
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.google.firebase.quickstart.ai.feature.text
2+
3+
import com.google.firebase.Firebase
4+
import com.google.firebase.ai.Chat
5+
import com.google.firebase.ai.ai
6+
import com.google.firebase.ai.type.Content
7+
import com.google.firebase.ai.type.GenerativeBackend
8+
import com.google.firebase.ai.type.content
9+
import com.google.firebase.quickstart.ai.ui.UiChatMessage
10+
import kotlinx.serialization.Serializable
11+
12+
@Serializable
13+
object TranslationRoute
14+
15+
class TranslationViewModel : ChatViewModel() {
16+
override val initialPrompt: String
17+
get() = """
18+
Translate the following text to Spanish:
19+
Hey, are you down to grab some pizza later? I'm starving!
20+
""".trimIndent()
21+
22+
private val chat: Chat
23+
24+
init {
25+
val generativeModel = Firebase.ai(
26+
backend = GenerativeBackend.googleAI()
27+
).generativeModel(
28+
modelName = "gemini-3.1-flash-lite-preview",
29+
systemInstruction = content {
30+
text("Only output the translated text")
31+
}
32+
)
33+
34+
chat = generativeModel.startChat()
35+
}
36+
37+
override suspend fun performSendMessage(
38+
prompt: Content,
39+
currentMessages: List<UiChatMessage>
40+
) {
41+
val response = chat.sendMessage(prompt)
42+
validateAndDisplayResponse(response, currentMessages)
43+
}
44+
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import com.google.firebase.quickstart.ai.feature.text.SvgRoute
3636
import com.google.firebase.quickstart.ai.feature.text.SvgViewModel
3737
import com.google.firebase.quickstart.ai.feature.text.ThinkingChatRoute
3838
import com.google.firebase.quickstart.ai.feature.text.ThinkingChatViewModel
39+
import com.google.firebase.quickstart.ai.feature.text.TranslationRoute
40+
import com.google.firebase.quickstart.ai.feature.text.TranslationViewModel
3941
import com.google.firebase.quickstart.ai.feature.text.TravelTipsRoute
4042
import com.google.firebase.quickstart.ai.feature.text.TravelTipsViewModel
4143
import com.google.firebase.quickstart.ai.feature.text.VideoHashtagGeneratorRoute
@@ -46,6 +48,14 @@ import com.google.firebase.quickstart.ai.feature.text.WeatherChatRoute
4648
import com.google.firebase.quickstart.ai.feature.text.WeatherChatViewModel
4749

4850
val FIREBASE_AI_SAMPLES = listOf(
51+
Sample(
52+
title = "Translate text",
53+
description = "Use Gemini 3.1 Flash-Lite to translate text",
54+
route = TranslationRoute,
55+
screenType = ScreenType.CHAT,
56+
viewModelClass = TranslationViewModel::class,
57+
categories = listOf(Category.TEXT)
58+
),
4959
Sample(
5060
title = "Travel tips",
5161
description = "The user wants the model to help a new traveler" +
@@ -65,7 +75,7 @@ val FIREBASE_AI_SAMPLES = listOf(
6575
),
6676
Sample(
6777
title = "Audio Summarization",
68-
description = "Summarize an audio file",
78+
description = "Use Gemini 3.1 Flash Lite to summarize an audio file",
6979
route = AudioSummarizationRoute,
7080
screenType = ScreenType.CHAT,
7181
viewModelClass = AudioSummarizationViewModel::class,
@@ -194,7 +204,7 @@ val FIREBASE_AI_SAMPLES = listOf(
194204
route = GoogleSearchGroundingRoute,
195205
screenType = ScreenType.CHAT,
196206
viewModelClass = GoogleSearchGroundingViewModel::class,
197-
categories = listOf(Category.TEXT, Category.DOCUMENT)
207+
categories = listOf(Category.TEXT)
198208
),
199209
Sample(
200210
title = "Server Prompt Template - Imagen",

0 commit comments

Comments
 (0)