From 8648f97c55300b0c1525d17b8cc7f3c09eba2773 Mon Sep 17 00:00:00 2001 From: Logan Kilpatrick Date: Mon, 16 Sep 2024 07:46:08 -0500 Subject: [PATCH] Update text_generation.kt --- .../generative/samples/text_generation.kt | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/samples/src/main/java/com/google/ai/client/generative/samples/text_generation.kt b/samples/src/main/java/com/google/ai/client/generative/samples/text_generation.kt index 86abc5d7..c78b44de 100644 --- a/samples/src/main/java/com/google/ai/client/generative/samples/text_generation.kt +++ b/samples/src/main/java/com/google/ai/client/generative/samples/text_generation.kt @@ -32,14 +32,12 @@ import com.google.ai.sample.R suspend fun textGenTextOnlyPrompt() { // [START text_gen_text_only_prompt] - val generativeModel = - GenerativeModel( - // Specify a Gemini model appropriate for your use case - modelName = "gemini-1.5-flash", - // Access your API key as a Build Configuration variable (see "Set up your API key" above) - apiKey = BuildConfig.apiKey) + import com.google.ai.client.generativeai.GenerativeModel + val geminiApiKey = BuildConfig.geminiApiKey - val prompt = "Write a story about a magic backpack." + val generativeModel = GenerativeModel( modelName = "gemini-1.5-flash", apiKey = BuildConfig.geminiApiKey) + + val prompt = "Explain how AI works" val response = generativeModel.generateContent(prompt) print(response.text) // [END text_gen_text_only_prompt] @@ -47,12 +45,10 @@ suspend fun textGenTextOnlyPrompt() { suspend fun textGenTextOnlyPromptStreaming() { // [START text_gen_text_only_prompt_streaming] - val generativeModel = - GenerativeModel( - // Specify a Gemini model appropriate for your use case - modelName = "gemini-1.5-flash", - // Access your API key as a Build Configuration variable (see "Set up your API key" above) - apiKey = BuildConfig.apiKey) + import com.google.ai.client.generativeai.GenerativeModel + val geminiApiKey = BuildConfig.geminiApiKey + + val generativeModel = GenerativeModel(modelName = "gemini-1.5-flash", apiKey = BuildConfig.apiKey) val prompt = "Write a story about a magic backpack." // Use streaming with text-only input