diff --git a/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/java/GoogleAISnippets.java b/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/java/GoogleAISnippets.java index eae4b311..bb9ab314 100644 --- a/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/java/GoogleAISnippets.java +++ b/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/java/GoogleAISnippets.java @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] @@ -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); @@ -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); diff --git a/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/java/VertexAISnippets.java b/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/java/VertexAISnippets.java index 0f199d10..73d2c966 100644 --- a/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/java/VertexAISnippets.java +++ b/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/java/VertexAISnippets.java @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] @@ -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); @@ -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); diff --git a/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/kotlin/CommonSnippets.kt b/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/kotlin/CommonSnippets.kt index baa41c9d..c3a9c0ae 100644 --- a/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/kotlin/CommonSnippets.kt +++ b/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/kotlin/CommonSnippets.kt @@ -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] } @@ -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. diff --git a/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/kotlin/GoogleAISnippets.kt b/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/kotlin/GoogleAISnippets.kt index bbff4aa6..ceaa456a 100644 --- a/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/kotlin/GoogleAISnippets.kt +++ b/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/kotlin/GoogleAISnippets.kt @@ -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] @@ -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] @@ -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] @@ -165,10 +171,11 @@ 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] } @@ -176,10 +183,11 @@ class GoogleAISnippets : ViewModel() { 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] } } \ No newline at end of file diff --git a/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/kotlin/VertexAISnippets.kt b/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/kotlin/VertexAISnippets.kt index 069bed49..23c6a6ba 100644 --- a/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/kotlin/VertexAISnippets.kt +++ b/firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/kotlin/VertexAISnippets.kt @@ -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] @@ -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] @@ -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] @@ -166,10 +172,11 @@ 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] } @@ -177,10 +184,11 @@ class VertexAISnippets : ViewModel() { 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] } }