Skip to content

Commit 7c135db

Browse files
committed
Modify Vertex AI generateContent() snippet
1 parent 65c7a76 commit 7c135db

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

misc/src/main/java/com/example/snippets/ai/VertexAiGeminiApi.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
package com.example.snippets.ai
1818

1919
import com.google.firebase.Firebase
20+
import com.google.firebase.ai.GenerativeModel
2021
import com.google.firebase.ai.ai
2122
import com.google.firebase.ai.type.GenerativeBackend
22-
import kotlinx.coroutines.CoroutineScope
23-
import kotlinx.coroutines.launch
2423

2524
class VertexAiGeminiApi {
2625

@@ -29,13 +28,12 @@ class VertexAiGeminiApi {
2928
.generativeModel("gemini-2.5-flash")
3029
// [END android_snippets_vertex_ai_gemini_api_model]
3130

32-
fun generateText(scope: CoroutineScope) {
33-
// [START android_snippets_vertex_ai_generate_content]
31+
// [START android_snippets_vertex_ai_generate_content]
32+
suspend fun generateText(model: GenerativeModel) {
3433
// Note: generateContent() is a suspend function, which integrates well
3534
// with existing Kotlin code.
36-
scope.launch {
37-
val response = model.generateContent("Write a story about a magic backpack.")
38-
}
39-
// [END android_snippets_vertex_ai_generate_content]
35+
val response = model.generateContent("Write a story about a magic backpack.")
36+
// ...
4037
}
38+
// [END android_snippets_vertex_ai_generate_content]
4139
}

0 commit comments

Comments
 (0)