Skip to content

Commit 60b6980

Browse files
committed
java time
1 parent 0376b3f commit 60b6980

File tree

3 files changed

+54
-25
lines changed

3 files changed

+54
-25
lines changed

firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/java/GoogleAISnippets.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ void functionCalling(FunctionDeclaration fetchWeatherTool) {
3838
GenerativeModelFutures.from(
3939
FirebaseAI.getInstance(GenerativeBackend.googleAI())
4040
.generativeModel(
41-
"gemini-2.5-flash",
42-
null,
43-
null,
41+
/* modelName */ "gemini-2.5-flash",
42+
/* generationConfig (optional) */ null,
43+
/* safetySettings (optional) */ null,
4444
// Provide the function declaration to the model.
4545
List.of(Tool.functionDeclarations(List.of(fetchWeatherTool)))));
4646
// [END function_calling_specify_declaration_during_init]
@@ -64,7 +64,9 @@ public void modelConfiguration_model_parameters_general() {
6464
GenerativeModelFutures model =
6565
GenerativeModelFutures.from(
6666
FirebaseAI.getInstance(GenerativeBackend.googleAI())
67-
.generativeModel("gemini-2.5-flash", config));
67+
.generativeModel(
68+
/* modelName */ "gemini-2.5-flash",
69+
/* generationConfig (optional) */ config));
6870

6971
// ...
7072
// [END model_parameters_general]
@@ -88,7 +90,10 @@ public void modelConfiguration_model_parameters_imagen() {
8890
// Specify the config as part of creating the `ImagenModel` instance
8991
ImagenModelFutures model =
9092
ImagenModelFutures.from(
91-
FirebaseAI.getInstance(GenerativeBackend.googleAI()).imagenModel("imagen-4.0-generate-001", config));
93+
FirebaseAI.getInstance(GenerativeBackend.googleAI())
94+
.imagenModel(
95+
/* modelName */ "imagen-4.0-generate-001",
96+
/* imagenGenerationConfig (optional) */ config));
9297

9398
// ...
9499
// [END model_parameters_imagen]
@@ -116,7 +121,9 @@ public void modelConfiguration_model_parameters_live() {
116121
LiveModelFutures model =
117122
LiveModelFutures.from(
118123
FirebaseAI.getInstance(GenerativeBackend.googleAI())
119-
.liveModel("gemini-2.5-flash", config));
124+
.liveModel(
125+
/* modelName */ "gemini-2.0-flash-live-preview-04-09",
126+
/* liveGenerationConfig (optional) */ config));
120127

121128
// ...
122129
// [END model_parameters_live]
@@ -129,7 +136,9 @@ public void modelConfiguration_safety_settings_imagen() {
129136
ImagenModelFutures model =
130137
ImagenModelFutures.from(
131138
FirebaseAI.getInstance(GenerativeBackend.googleAI())
132-
.imagenModel(/* modelName */ "imagen-4.0-generate-001", /* imageGenerationConfig */ null));
139+
.imagenModel(
140+
/* modelName */ "imagen-4.0-generate-001",
141+
/* imageGenerationConfig (optional) */ null));
133142

134143
// ...
135144
// [END safety_settings_imagen]
@@ -184,7 +193,9 @@ public void systemInstructions_general() {
184193
/* safetySettings (optional) */ null,
185194
/* tools (optional) */ null,
186195
/* toolConfig (optional) */ null,
187-
/* systemInstructions (optional) */ new Content.Builder().addText("You are a cat. Your name is Neko.").build()
196+
/* systemInstructions (optional) */ new Content.Builder()
197+
.addText("You are a cat. Your name is Neko.")
198+
.build()
188199
);
189200

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

206219
LiveModelFutures model = LiveModelFutures.from(ai);

firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/java/VertexAISnippets.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ void functionCalling(FunctionDeclaration fetchWeatherTool) {
3939
GenerativeModelFutures.from(
4040
FirebaseAI.getInstance(GenerativeBackend.vertexAI("global"))
4141
.generativeModel(
42-
"gemini-2.5-flash",
43-
null,
44-
null,
42+
/* modelName */ "gemini-2.5-flash",
43+
/* generationConfig (optional) */ null,
44+
/* safetySettings (optional) */ null,
4545
// Provide the function declaration to the model.
4646
List.of(Tool.functionDeclarations(List.of(fetchWeatherTool)))));
4747
// [END function_calling_specify_declaration_during_init]
@@ -65,7 +65,9 @@ public void modelConfiguration_model_parameters_general() {
6565
GenerativeModelFutures model =
6666
GenerativeModelFutures.from(
6767
FirebaseAI.getInstance(GenerativeBackend.vertexAI())
68-
.generativeModel("gemini-2.5-flash", config));
68+
.generativeModel(
69+
/* modelName */ "gemini-2.5-flash",
70+
/* generationConfig (optional) */ null));
6971

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

9498
// ...
9599
// [END model_parameters_imagen]
@@ -117,7 +121,9 @@ public void modelConfiguration_model_parameters_live() {
117121
LiveModelFutures model =
118122
LiveModelFutures.from(
119123
FirebaseAI.getInstance(GenerativeBackend.vertexAI())
120-
.liveModel("gemini-2.5-flash", config));
124+
.liveModel(
125+
/* modelName */ "gemini-2.0-flash-live-preview-04-09",
126+
/* liveGenerationConfig (optional) */ config));
121127

122128
// ...
123129
// [END model_parameters_live]
@@ -130,7 +136,9 @@ public void modelConfiguration_safety_settings_imagen() {
130136
ImagenModelFutures model =
131137
ImagenModelFutures.from(
132138
FirebaseAI.getInstance(GenerativeBackend.vertexAI())
133-
.imagenModel(/* modelName */ "imagen-4.0-generate-001", /* imageGenerationConfig */ null));
139+
.imagenModel(
140+
/* modelName */ "imagen-4.0-generate-001",
141+
/* imageGenerationConfig */ null));
134142

135143
// ...
136144
// [END safety_settings_imagen]
@@ -151,7 +159,7 @@ public void modelConfiguration_safety_settings_multiple() {
151159
.generativeModel(
152160
/* modelName */ "gemini-2.5-flash",
153161
/* generationConfig is optional */ null,
154-
List.of(harassmentSafety, hateSpeechSafety)));
162+
/* safetySettings */ List.of(harassmentSafety, hateSpeechSafety)));
155163

156164
// ...
157165
// [END safety_settings_multiple]
@@ -169,7 +177,7 @@ public void modelConfiguration_safety_settings_single() {
169177
.generativeModel(
170178
/* modelName */ "gemini-2.5-flash",
171179
/* generationConfig is optional */ null,
172-
Collections.singletonList(harassmentSafety)));
180+
/* safetySettings */ Collections.singletonList(harassmentSafety)));
173181

174182
// ...
175183
// [END safety_settings_single]
@@ -185,7 +193,9 @@ public void systemInstructions_general() {
185193
/* safetySettings (optional) */ null,
186194
/* tools (optional) */ null,
187195
/* toolsConfig (optional) */ null,
188-
/* systemInstruction (optional) */ new Content.Builder().addText("You are a cat. Your name is Neko.").build()
196+
/* systemInstruction (optional) */ new Content.Builder()
197+
.addText("You are a cat. Your name is Neko.")
198+
.build()
189199
);
190200

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

207219
LiveModelFutures model = LiveModelFutures.from(ai);

firebase-ai/app/src/main/java/com/google/firebase/example/ailogic/kotlin/CommonSnippets.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ class CommonSnippets(
5757
)
5858
)
5959

60-
chat.sendMessageStream("How many paws are in my house?").collect { chunk -> print(chunk.text) }
60+
chat.sendMessageStream("How many paws are in my house?").collect {
61+
chunk -> print(chunk.text)
62+
}
6163
// [END chat_streaming]
6264
}
6365

@@ -119,7 +121,9 @@ class CommonSnippets(
119121
// so that the model can use it to generate its final response.
120122
val finalResponse =
121123
chat.sendMessage(
122-
content("function") { part(FunctionResponsePart("fetchWeather", functionResponse!!)) }
124+
content("function") {
125+
part(FunctionResponsePart("fetchWeather", functionResponse!!))
126+
}
123127
)
124128

125129
// Log the text response.

0 commit comments

Comments
 (0)