Skip to content
Merged
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 @@ -38,9 +38,9 @@ void functionCalling(FunctionDeclaration fetchWeatherTool) {
GenerativeModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel(
"gemini-2.5-flash",
null,
null,
/* modelName */ "gemini-2.5-flash",
/* generationConfig (optional) */ null,
/* safetySettings (optional) */ null,
// Provide the function declaration to the model.
List.of(Tool.functionDeclarations(List.of(fetchWeatherTool)))));
// [END function_calling_specify_declaration_during_init]
Expand All @@ -64,7 +64,9 @@ public void modelConfiguration_model_parameters_general() {
GenerativeModelFutures model =
GenerativeModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel("gemini-2.5-flash", config));
.generativeModel(
/* modelName */ "gemini-2.5-flash",
/* generationConfig (optional) */ config));

// ...
// [END model_parameters_general]
Expand All @@ -88,7 +90,10 @@ public void modelConfiguration_model_parameters_imagen() {
// Specify the config as part of creating the `ImagenModel` instance
ImagenModelFutures model =
ImagenModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI()).imagenModel("imagen-4.0-generate-001", config));
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.imagenModel(
/* modelName */ "imagen-4.0-generate-001",
/* imagenGenerationConfig (optional) */ config));

// ...
// [END model_parameters_imagen]
Expand Down Expand Up @@ -116,7 +121,9 @@ public void modelConfiguration_model_parameters_live() {
LiveModelFutures model =
LiveModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.liveModel("gemini-2.5-flash", config));
.liveModel(
/* modelName */ "gemini-2.0-flash-live-preview-04-09",
/* liveGenerationConfig (optional) */ config));

// ...
// [END model_parameters_live]
Expand All @@ -129,7 +136,9 @@ public void modelConfiguration_safety_settings_imagen() {
ImagenModelFutures model =
ImagenModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.imagenModel(/* modelName */ "imagen-4.0-generate-001", /* imageGenerationConfig */ null));
.imagenModel(
/* modelName */ "imagen-4.0-generate-001",
/* imageGenerationConfig (optional) */ null));

// ...
// [END safety_settings_imagen]
Expand Down Expand Up @@ -184,7 +193,9 @@ public void systemInstructions_general() {
/* safetySettings (optional) */ null,
/* tools (optional) */ null,
/* toolConfig (optional) */ null,
/* systemInstructions (optional) */ new Content.Builder().addText("You are a cat. Your name is Neko.").build()
/* systemInstructions (optional) */ new Content.Builder()
.addText("You are a cat. Your name is Neko.")
.build()
);

GenerativeModelFutures model = GenerativeModelFutures.from(ai);
Expand All @@ -197,10 +208,12 @@ public void systemInstructions_live() {
// Specify the system instructions as part of creating the `LiveModel` instance
LiveGenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
.liveModel(
/* modelName */ "gemini-2.5-flash",
/* generationConfig (optional) */ null,
/* modelName */ "gemini-2.0-flash-live-preview-04-09",
/* liveGenerationConfig (optional) */ null,
/* tools (optional) */ null,
/* systemInstructions (optional) */ new Content.Builder().addText("You are a cat. Your name is Neko.").build()
/* systemInstructions (optional) */ new Content.Builder()
.addText("You are a cat. Your name is Neko.")
.build()
);

LiveModelFutures model = LiveModelFutures.from(ai);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ void functionCalling(FunctionDeclaration fetchWeatherTool) {
GenerativeModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.vertexAI("global"))
.generativeModel(
"gemini-2.5-flash",
null,
null,
/* modelName */ "gemini-2.5-flash",
/* generationConfig (optional) */ null,
/* safetySettings (optional) */ null,
// Provide the function declaration to the model.
List.of(Tool.functionDeclarations(List.of(fetchWeatherTool)))));
// [END function_calling_specify_declaration_during_init]
Expand All @@ -65,7 +65,9 @@ public void modelConfiguration_model_parameters_general() {
GenerativeModelFutures model =
GenerativeModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.vertexAI())
.generativeModel("gemini-2.5-flash", config));
.generativeModel(
/* modelName */ "gemini-2.5-flash",
/* generationConfig (optional) */ null));

// ...
// [END model_parameters_general]
Expand All @@ -89,7 +91,9 @@ public void modelConfiguration_model_parameters_imagen() {
// Specify the config as part of creating the `ImagenModel` instance
ImagenModelFutures model =
ImagenModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.vertexAI()).imagenModel("imagen-4.0-generate-001", config));
FirebaseAI.getInstance(GenerativeBackend.vertexAI()).imagenModel(
/* modelName */ "imagen-4.0-generate-001",
/* imagenGenerationConfig (optional) */ config));

// ...
// [END model_parameters_imagen]
Expand Down Expand Up @@ -117,7 +121,9 @@ public void modelConfiguration_model_parameters_live() {
LiveModelFutures model =
LiveModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.vertexAI())
.liveModel("gemini-2.5-flash", config));
.liveModel(
/* modelName */ "gemini-2.0-flash-live-preview-04-09",
/* liveGenerationConfig (optional) */ config));

// ...
// [END model_parameters_live]
Expand All @@ -130,7 +136,9 @@ public void modelConfiguration_safety_settings_imagen() {
ImagenModelFutures model =
ImagenModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.vertexAI())
.imagenModel(/* modelName */ "imagen-4.0-generate-001", /* imageGenerationConfig */ null));
.imagenModel(
/* modelName */ "imagen-4.0-generate-001",
/* imageGenerationConfig */ null));

// ...
// [END safety_settings_imagen]
Expand All @@ -151,7 +159,7 @@ public void modelConfiguration_safety_settings_multiple() {
.generativeModel(
/* modelName */ "gemini-2.5-flash",
/* generationConfig is optional */ null,
List.of(harassmentSafety, hateSpeechSafety)));
/* safetySettings */ List.of(harassmentSafety, hateSpeechSafety)));

// ...
// [END safety_settings_multiple]
Expand All @@ -169,7 +177,7 @@ public void modelConfiguration_safety_settings_single() {
.generativeModel(
/* modelName */ "gemini-2.5-flash",
/* generationConfig is optional */ null,
Collections.singletonList(harassmentSafety)));
/* safetySettings */ Collections.singletonList(harassmentSafety)));

// ...
// [END safety_settings_single]
Expand All @@ -185,7 +193,9 @@ public void systemInstructions_general() {
/* safetySettings (optional) */ null,
/* tools (optional) */ null,
/* toolsConfig (optional) */ null,
/* systemInstruction (optional) */ new Content.Builder().addText("You are a cat. Your name is Neko.").build()
/* systemInstruction (optional) */ new Content.Builder()
.addText("You are a cat. Your name is Neko.")
.build()
);

GenerativeModelFutures model = GenerativeModelFutures.from(ai);
Expand All @@ -198,10 +208,12 @@ public void systemInstructions_live() {
// Specify the system instructions as part of creating the `LiveModel` instance
LiveGenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.vertexAI())
.liveModel(
/* modelName */ "gemini-2.5-flash",
/* modelName */ "gemini-2.0-flash-live-preview-04-09",
/* generationConfig (optional) */ null,
/* tools (optional) */ null,
/* systemInstruction (optional) */ new Content.Builder().addText("You are a cat. Your name is Neko.").build()
/* systemInstruction (optional) */ new Content.Builder()
.addText("You are a cat. Your name is Neko.")
.build()
);

LiveModelFutures model = LiveModelFutures.from(ai);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class CommonSnippets(
)
)

chat.sendMessageStream("How many paws are in my house?").collect { chunk -> print(chunk.text) }
chat.sendMessageStream("How many paws are in my house?").collect {
chunk -> print(chunk.text)
}
// [END chat_streaming]
}

Expand Down Expand Up @@ -119,7 +121,9 @@ class CommonSnippets(
// so that the model can use it to generate its final response.
val finalResponse =
chat.sendMessage(
content("function") { part(FunctionResponsePart("fetchWeather", functionResponse!!)) }
content("function") {
part(FunctionResponsePart("fetchWeather", functionResponse!!))
}
)

// Log the text response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ class GoogleAISnippets : ViewModel() {
// Specify the config as part of creating the `GenerativeModel` instance
val model =
Firebase.ai(backend = GenerativeBackend.googleAI())
.generativeModel(modelName = "gemini-2.5-flash", generationConfig = config)
.generativeModel(
modelName = "gemini-2.5-flash",
generationConfig = config)

// ...
// [END model_parameters_general]
Expand All @@ -79,7 +81,9 @@ class GoogleAISnippets : ViewModel() {
// Specify the config as part of creating the `GenerativeModel` instance
val model =
Firebase.ai(backend = GenerativeBackend.vertexAI())
.imagenModel(modelName = "imagen-4.0-generate-001", generationConfig = config)
.imagenModel(
modelName = "imagen-4.0-generate-001",
generationConfig = config)

// ...
// [END model_parameters_imagen]
Expand All @@ -104,7 +108,9 @@ class GoogleAISnippets : ViewModel() {
// Specify the config as part of creating the `LiveModel` instance
val model =
Firebase.ai(backend = GenerativeBackend.googleAI())
.liveModel(modelName = "gemini-2.5-flash", generationConfig = config)
.liveModel(
modelName = "gemini-2.0-flash-live-preview-04-09",
generationConfig = config)

// ...
// [END model_parameters_live]
Expand Down Expand Up @@ -165,21 +171,23 @@ class GoogleAISnippets : ViewModel() {
fun systemInstructions_general() {
// [START system_instructions_general]
// Specify the system instructions as part of creating the `GenerativeModel` instance
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "gemini-2.5-flash",
systemInstruction = content { text("You are a cat. Your name is Neko.") }
)
val model = Firebase.ai(backend = GenerativeBackend.googleAI())
.generativeModel(
modelName = "gemini-2.5-flash",
systemInstruction = content { text("You are a cat. Your name is Neko.") }
)
// [END system_instructions_general]
}

@OptIn(PublicPreviewAPI::class)
fun systemInstructions_live() {
// [START system_instructions_live]
// Specify the system instructions as part of creating the `LiveModel` instance
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel(
modelName = "gemini-2.5-flash",
systemInstruction = content { text("You are a cat. Your name is Neko.") }
)
val model = Firebase.ai(backend = GenerativeBackend.googleAI())
.liveModel(
modelName = "gemini-2.0-flash-live-preview-04-09",
systemInstruction = content { text("You are a cat. Your name is Neko.") }
)
// [END system_instructions_live]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class VertexAISnippets : ViewModel() {
// Specify the config as part of creating the `GenerativeModel` instance
val model =
Firebase.ai(backend = GenerativeBackend.vertexAI())
.generativeModel(modelName = "gemini-2.5-flash", generationConfig = config)
.generativeModel(
modelName = "gemini-2.5-flash",
generationConfig = config)

// ...
// [END model_parameters_general]
Expand All @@ -80,7 +82,9 @@ class VertexAISnippets : ViewModel() {
// Specify the config as part of creating the `GenerativeModel` instance
val model =
Firebase.ai(backend = GenerativeBackend.vertexAI())
.imagenModel(modelName = "imagen-4.0-generate-001", generationConfig = config)
.imagenModel(
modelName = "imagen-4.0-generate-001",
generationConfig = config)

// ...
// [END model_parameters_imagen]
Expand All @@ -105,7 +109,9 @@ class VertexAISnippets : ViewModel() {
// Specify the config as part of creating the `LiveModel` instance
val model =
Firebase.ai(backend = GenerativeBackend.vertexAI())
.liveModel(modelName = "gemini-2.5-flash", generationConfig = config)
.liveModel(
modelName = "gemini-2.0-flash-live-preview-04-09",
generationConfig = config)

// ...
// [END model_parameters_live]
Expand Down Expand Up @@ -166,21 +172,23 @@ class VertexAISnippets : ViewModel() {
fun systemInstructions_general() {
// [START system_instructions_general]
// Specify the system instructions as part of creating the `GenerativeModel` instance
val model = Firebase.ai(backend = GenerativeBackend.vertexAI()).generativeModel(
modelName = "gemini-2.5-flash",
systemInstruction = content { text("You are a cat. Your name is Neko.") }
)
val model = Firebase.ai(backend = GenerativeBackend.vertexAI())
.generativeModel(
modelName = "gemini-2.5-flash",
systemInstruction = content { text("You are a cat. Your name is Neko.") }
)
// [END system_instructions_general]
}

@OptIn(PublicPreviewAPI::class)
fun systemInstructions_live() {
// [START system_instructions_live]
// Specify the system instructions as part of creating the `LiveModel` instance
val model = Firebase.ai(backend = GenerativeBackend.vertexAI()).liveModel(
modelName = "gemini-2.5-flash",
systemInstruction = content { text("You are a cat. Your name is Neko.") }
)
val model = Firebase.ai(backend = GenerativeBackend.vertexAI())
.liveModel(
modelName = "gemini-2.0-flash-live-preview-04-09",
systemInstruction = content { text("You are a cat. Your name is Neko.") }
)
// [END system_instructions_live]
}
}