Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: rachelsaunders <[email protected]>
  • Loading branch information
rlazo and rachelsaunders authored Jun 24, 2024
1 parent 0694a99 commit 5a5d0c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void systemInstructions() {
// [START system_instructions]
GenerativeModel model =
new GenerativeModel(
// Specify a Gemini model appropriate for your use case
/* modelName */ "gemini-1.5-flash",
/* apiKey */ BuildConfig.apiKey,
/* generationConfig (optional) */ null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ import com.google.ai.client.generativeai.GenerativeModel
import com.google.ai.client.generativeai.type.content

suspend fun textGenTextOnlyPrompt() {
// [START text_gen_text-only-prompt]
// [START text_gen_text_only_prompt]
val generativeModel =
GenerativeModel(
// The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts
// 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)

val prompt = "Write a story about a magic backpack."
val response = generativeModel.generateContent(prompt)
print(response.text)
// [END text_gen_text-only-prompt]
// [END text_gen_text_only_prompt]
}

suspend fun textGenTextOnlyPromptStreaming() {
// [START text_gen_text-only-prompt_streaming]
// [START text_gen_text_only_prompt_streaming]
val generativeModel =
GenerativeModel(
// The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts
// 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)
Expand All @@ -47,14 +47,14 @@ suspend fun textGenTextOnlyPromptStreaming() {
// Use streaming with text-only input
generativeModel.generateContentStream(prompt).collect { chunk -> print(chunk.text) }

// [END text_gen_text-only-prompt_streaming]
// [END text_gen_text_only_prompt_streaming]
}

suspend fun textGenMultimodalOneImagePrompt() {
// [START text_gen_multimodal-one-image-prompt]
// [START text_gen_multimodal_one_image_prompt]
val generativeModel =
GenerativeModel(
// The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts
// 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)
Expand All @@ -63,29 +63,29 @@ suspend fun textGenMultimodalOneImagePrompt() {

val response = generativeModel.generateContent(inputContent)
print(response.text)
// [END text_gen_multimodal-one-image-prompt]
// [END text_gen_multimodal_one_image_prompt]
}

suspend fun textGenMultimodalOneImagePromptStreaming() {
// [START text_gen_multimodal-one-image-prompt_streaming]
// [START text_gen_multimodal_one_image_prompt_streaming]
val generativeModel =
GenerativeModel(
// The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts
// 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)

val inputContent = content { text("What's in this picture?") }

generativeModel.generateContentStream(inputContent).collect { chunk -> print(chunk.text) }
// [END text_gen_multimodal-one-image-prompt_streaming]
// [END text_gen_multimodal_one_image_prompt_streaming]
}

suspend fun textGenMultimodalMultiImagePrompt() {
// [START text_gen_multimodal-multi-image-prompt]
// [START text_gen_multimodal_multi_image_prompt]
val generativeModel =
GenerativeModel(
// The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts
// 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)
Expand All @@ -95,32 +95,32 @@ suspend fun textGenMultimodalMultiImagePrompt() {
val response = generativeModel.generateContent(inputContent)
print(response.text)

// [END text_gen_multimodal-multi-image-prompt]
// [END text_gen_multimodal_multi_image_prompt]
}

suspend fun textGenMultimodalMultiImagePromptStreaming() {
// [START text_gen_multimodal-multi-image-prompt_streaming]
// [START text_gen_multimodal_multi_image_prompt_streaming]
val generativeModel =
GenerativeModel(
// The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts
// 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)

val inputContent = content { text("What's different between these pictures?") }

generativeModel.generateContentStream(inputContent).collect { chunk -> print(chunk.text) }
// [END text_gen_multimodal-multi-image-prompt_streaming]
// [END text_gen_multimodal_multi_image_prompt_streaming]
}

suspend fun textGenMultimodalVideoPrompt() {
// [START text_gen_multimodal-video-prompt]
// [START text_gen_multimodal_video_prompt]
// TODO
// [END text_gen_multimodal-video-prompt]
// [END text_gen_multimodal_video_prompt]
}

suspend fun textGenMultimodalVideoPromptStreaming() {
// [START text_gen_multimodal-video-prompt_streaming]
// [START text_gen_multimodal_video_prompt_streaming]
// TODO
// [END text_gen_multimodal-video-prompt_streaming]
// [END text_gen_multimodal_video_prompt_streaming]
}

0 comments on commit 5a5d0c8

Please sign in to comment.