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 2061786 commit ae8b3ec
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ suspend fun chatStreamingWithImages(context: Context) {
// Use streaming with multi-turn conversations (like chat)
val generativeModel =
GenerativeModel(
// The Gemini 1.5 models are versatile and work with multi-turn conversations (like chat)
// 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

class SafetySettings {
void safetySettings() {
// [START safety-settings]
// [START safety_settings]
SafetySetting harassmentSafety =
new SafetySetting(HarmCategory.HARASSMENT, BlockThreshold.ONLY_HIGH);

// The Gemini 1.5 models are versatile and work with most use cases
// Specify a Gemini model appropriate for your use case
GenerativeModel gm =
new GenerativeModel(
"gemini-1.5-flash",
Expand All @@ -37,7 +37,7 @@ void safetySettings() {
Collections.singletonList(harassmentSafety));

GenerativeModelFutures model = GenerativeModelFutures.from(gm);
// [END safety-settings]
// [END safety_settings]
}

void SafetySettingsMulti() {
Expand All @@ -48,7 +48,7 @@ void SafetySettingsMulti() {
SafetySetting hateSpeechSafety =
new SafetySetting(HarmCategory.HATE_SPEECH, BlockThreshold.MEDIUM_AND_ABOVE);

// The Gemini 1.5 models are versatile and work with most use cases
// Specify a Gemini model appropriate for your use case
GenerativeModel gm =
new GenerativeModel(
"gemini-1.5-flash",
Expand All @@ -57,6 +57,6 @@ void SafetySettingsMulti() {
Arrays.asList(harassmentSafety, hateSpeechSafety));

GenerativeModelFutures model = GenerativeModelFutures.from(gm);
// [END safety-settings_multi]
// [END safety_settings_multi]
}
}
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
// Specify a Gemini model appropriate for your use case
/* modelName */ "gemini-1.5-flash",
/* apiKey */ BuildConfig.apiKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@

class TextGeneration {
void TextGenTextOnlyPrompt() {
// [START text_gen_text-only-prompt]
// The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts
// [START text_gen_text_only_prompt]
// Specify a Gemini model appropriate for your use case
GenerativeModel gm =
new GenerativeModel(
/* modelName */ "gemini-1.5-flash",
Expand Down Expand Up @@ -65,12 +65,12 @@ public void onFailure(Throwable t) {
}
},
executor);
// [END text_gen_text-only-prompt]
// [END text_gen_text_only_prompt]
}

void TextGenTextOnlyPromptStreaming() {
// [START text_gen_text-only-prompt_streaming]
// The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts
// [START text_gen_text_only_prompt_streaming]
// Specify a Gemini model appropriate for your use case
GenerativeModel gm =
new GenerativeModel(
/* modelName */ "gemini-1.5-flash",
Expand Down Expand Up @@ -109,12 +109,12 @@ public void onSubscribe(Subscription s) {
s.request(Long.MAX_VALUE);
}
});
// [END text_gen_text-only-prompt_streaming]
// [END text_gen_text_only_prompt_streaming]
}

void TextGenMultimodalOneImagePrompt(Context context) {
// [START text_gen_multimodal-one-image-prompt]
// The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts
// [START text_gen_multimodal_one_image_prompt]
// Specify a Gemini model appropriate for your use case
GenerativeModel gm =
new GenerativeModel(
/* modelName */ "gemini-1.5-flash",
Expand Down Expand Up @@ -150,12 +150,12 @@ public void onFailure(Throwable t) {
}
},
executor);
// [END text_gen_multimodal-one-image-prompt]
// [END text_gen_multimodal_one_image_prompt]
}

void TextGenMultimodalOneImagePromptStreaming(Context context) {
// [START text_gen_multimodal-one-image-prompt_streaming]
// The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts
// [START text_gen_multimodal_one_image_prompt_streaming]
// Specify a Gemini model appropriate for your use case
GenerativeModel gm =
new GenerativeModel(
/* modelName */ "gemini-1.5-flash",
Expand Down Expand Up @@ -204,12 +204,12 @@ public void onSubscribe(Subscription s) {
s.request(Long.MAX_VALUE);
}
});
// [END text_gen_multimodal-one-image-prompt_streaming]
// [END text_gen_multimodal_one_image_prompt_streaming]
}

void TextGenMultimodalMultiImagePrompt(Context context) {
// [START text_gen_multimodal-multi-image-prompt]
// 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
GenerativeModel gm =
new GenerativeModel(
/* modelName */ "gemini-1.5-flash",
Expand Down Expand Up @@ -247,12 +247,12 @@ public void onFailure(Throwable t) {
}
},
executor);
// [END text_gen_multimodal-multi-image-prompt]
// [END text_gen_multimodal_multi_image_prompt]
}

void TextGenMultimodalMultiImagePromptStreaming(Context context) {
// [START text_gen_multimodal-multi-image-prompt_streaming]
// The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts
// [START text_gen_multimodal_multi_image_prompt_streaming]
// Specify a Gemini model appropriate for your use case
GenerativeModel gm =
new GenerativeModel(
/* modelName */ "gemini-1.5-flash",
Expand Down Expand Up @@ -300,18 +300,18 @@ public void onSubscribe(Subscription s) {
s.request(Long.MAX_VALUE);
}
});
// [END text_gen_multimodal-multi-image-prompt_streaming]
// [END text_gen_multimodal_multi_image_prompt_streaming]
}

void 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]
}

void 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]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ suspend fun configureModel() {

val generativeModel =
GenerativeModel(
// The Gemini 1.5 models are versatile and work with most use cases
// Specify a Gemini model appropriate for your use case
modelName = "gemini-1.5-flash",
apiKey = BuildConfig.apiKey,
generationConfig = config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ suspend fun safetySettings() {
// [START safety-settings]
val generativeModel =
GenerativeModel(
// The Gemini 1.5 models are versatile and work with most use cases
// Specify a Gemini model appropriate for your use case
modelName = "gemini-1.5-flash",
apiKey = BuildConfig.apiKey,
safetySettings = listOf(SafetySetting(HarmCategory.HARASSMENT, BlockThreshold.ONLY_HIGH)))
// [END safety-settings]
}

suspend fun SafetySettingsMulti() {
// [START safety-settings_multi]
// [START safety_settings_multi]
val harassmentSafety = SafetySetting(HarmCategory.HARASSMENT, BlockThreshold.ONLY_HIGH)

val hateSpeechSafety = SafetySetting(HarmCategory.HATE_SPEECH, BlockThreshold.MEDIUM_AND_ABOVE)
Expand All @@ -44,5 +44,5 @@ suspend fun SafetySettingsMulti() {
modelName = "gemini-1.5-flash",
apiKey = BuildConfig.apiKey,
safetySettings = listOf(harassmentSafety, hateSpeechSafety))
// [END safety-settings_multi]
// [END safety_settings_multi]
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ suspend fun systemInstructions() {
// [START system_instructions]
val generativeModel =
GenerativeModel(
// Specify a Gemini model appropriate for your use case
modelName = "gemini-1.5-flash",
apiKey = BuildConfig.apiKey,
systemInstruction = content { text("You are a cat. Your name is Neko.") },
Expand Down

0 comments on commit ae8b3ec

Please sign in to comment.