Skip to content

Commit 9bc17c8

Browse files
authored
refactor(ai): adjust indentation on snippets (#648)
1 parent 872ffd6 commit 9bc17c8

File tree

5 files changed

+92
-47
lines changed

5 files changed

+92
-47
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.

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ class GoogleAISnippets : ViewModel() {
5555
// Specify the config as part of creating the `GenerativeModel` instance
5656
val model =
5757
Firebase.ai(backend = GenerativeBackend.googleAI())
58-
.generativeModel(modelName = "gemini-2.5-flash", generationConfig = config)
58+
.generativeModel(
59+
modelName = "gemini-2.5-flash",
60+
generationConfig = config)
5961

6062
// ...
6163
// [END model_parameters_general]
@@ -79,7 +81,9 @@ class GoogleAISnippets : ViewModel() {
7981
// Specify the config as part of creating the `GenerativeModel` instance
8082
val model =
8183
Firebase.ai(backend = GenerativeBackend.vertexAI())
82-
.imagenModel(modelName = "imagen-4.0-generate-001", generationConfig = config)
84+
.imagenModel(
85+
modelName = "imagen-4.0-generate-001",
86+
generationConfig = config)
8387

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

109115
// ...
110116
// [END model_parameters_live]
@@ -165,21 +171,23 @@ class GoogleAISnippets : ViewModel() {
165171
fun systemInstructions_general() {
166172
// [START system_instructions_general]
167173
// Specify the system instructions as part of creating the `GenerativeModel` instance
168-
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
169-
modelName = "gemini-2.5-flash",
170-
systemInstruction = content { text("You are a cat. Your name is Neko.") }
171-
)
174+
val model = Firebase.ai(backend = GenerativeBackend.googleAI())
175+
.generativeModel(
176+
modelName = "gemini-2.5-flash",
177+
systemInstruction = content { text("You are a cat. Your name is Neko.") }
178+
)
172179
// [END system_instructions_general]
173180
}
174181

175182
@OptIn(PublicPreviewAPI::class)
176183
fun systemInstructions_live() {
177184
// [START system_instructions_live]
178185
// Specify the system instructions as part of creating the `LiveModel` instance
179-
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel(
180-
modelName = "gemini-2.5-flash",
181-
systemInstruction = content { text("You are a cat. Your name is Neko.") }
182-
)
186+
val model = Firebase.ai(backend = GenerativeBackend.googleAI())
187+
.liveModel(
188+
modelName = "gemini-2.0-flash-live-preview-04-09",
189+
systemInstruction = content { text("You are a cat. Your name is Neko.") }
190+
)
183191
// [END system_instructions_live]
184192
}
185193
}

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ class VertexAISnippets : ViewModel() {
5656
// Specify the config as part of creating the `GenerativeModel` instance
5757
val model =
5858
Firebase.ai(backend = GenerativeBackend.vertexAI())
59-
.generativeModel(modelName = "gemini-2.5-flash", generationConfig = config)
59+
.generativeModel(
60+
modelName = "gemini-2.5-flash",
61+
generationConfig = config)
6062

6163
// ...
6264
// [END model_parameters_general]
@@ -80,7 +82,9 @@ class VertexAISnippets : ViewModel() {
8082
// Specify the config as part of creating the `GenerativeModel` instance
8183
val model =
8284
Firebase.ai(backend = GenerativeBackend.vertexAI())
83-
.imagenModel(modelName = "imagen-4.0-generate-001", generationConfig = config)
85+
.imagenModel(
86+
modelName = "imagen-4.0-generate-001",
87+
generationConfig = config)
8488

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

110116
// ...
111117
// [END model_parameters_live]
@@ -166,21 +172,23 @@ class VertexAISnippets : ViewModel() {
166172
fun systemInstructions_general() {
167173
// [START system_instructions_general]
168174
// Specify the system instructions as part of creating the `GenerativeModel` instance
169-
val model = Firebase.ai(backend = GenerativeBackend.vertexAI()).generativeModel(
170-
modelName = "gemini-2.5-flash",
171-
systemInstruction = content { text("You are a cat. Your name is Neko.") }
172-
)
175+
val model = Firebase.ai(backend = GenerativeBackend.vertexAI())
176+
.generativeModel(
177+
modelName = "gemini-2.5-flash",
178+
systemInstruction = content { text("You are a cat. Your name is Neko.") }
179+
)
173180
// [END system_instructions_general]
174181
}
175182

176183
@OptIn(PublicPreviewAPI::class)
177184
fun systemInstructions_live() {
178185
// [START system_instructions_live]
179186
// Specify the system instructions as part of creating the `LiveModel` instance
180-
val model = Firebase.ai(backend = GenerativeBackend.vertexAI()).liveModel(
181-
modelName = "gemini-2.5-flash",
182-
systemInstruction = content { text("You are a cat. Your name is Neko.") }
183-
)
187+
val model = Firebase.ai(backend = GenerativeBackend.vertexAI())
188+
.liveModel(
189+
modelName = "gemini-2.0-flash-live-preview-04-09",
190+
systemInstruction = content { text("You are a cat. Your name is Neko.") }
191+
)
184192
// [END system_instructions_live]
185193
}
186194
}

0 commit comments

Comments
 (0)