Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class TextGeneration {
void TextGenTextOnlyPrompt() {
// [START text_gen_text_only_prompt]
// Specify a Gemini model appropriate for your use case
import com.google.ai.client.generativeai.GenerativeModel;
import com.google.ai.client.generativeai.java.GenerativeModelFutures;
import com.google.ai.client.generativeai.type.Content;
import com.google.ai.client.generativeai.type.GenerateContentResponse;

GenerativeModel gm =
new GenerativeModel(
/* modelName */ "gemini-1.5-flash",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,23 @@ 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]
}

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
Expand Down
Loading