Skip to content

Commit eb7729b

Browse files
committed
chore: minor cleanup of the gemini sample
1 parent 04aad0a commit eb7729b

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

samples/js-gemini/src/index.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ const getWeather = ai.defineTool(
118118
'Location for which to get the weather, ex: San-Francisco, CA'
119119
),
120120
}),
121-
description: 'can be used to calculate gablorken value',
121+
description: 'used to get current weather for a location',
122122
},
123123
async (input) => {
124124
// pretend we call an actual API
@@ -130,6 +130,19 @@ const getWeather = ai.defineTool(
130130
}
131131
);
132132

133+
const celsiusToFahrenheit = ai.defineTool(
134+
{
135+
name: 'celsiusToFahrenheit',
136+
inputSchema: z.object({
137+
celsius: z.number().describe('Temperature in Celsius'),
138+
}),
139+
description: 'Converts Celsius to Fahrenheit',
140+
},
141+
async ({ celsius }) => {
142+
return (celsius * 9) / 5 + 32;
143+
}
144+
);
145+
133146
// Tool calling with Gemini
134147
ai.defineFlow(
135148
{
@@ -144,8 +157,8 @@ ai.defineFlow(
144157
config: {
145158
temperature: 1,
146159
},
147-
tools: [getWeather],
148-
prompt: `tell what's the weather in ${location} (in Fahrenheit)`,
160+
tools: [getWeather, celsiusToFahrenheit],
161+
prompt: `What's the weather in ${location}? Convert the temperature to Fahrenheit.`,
149162
});
150163

151164
for await (const chunk of stream) {
@@ -181,7 +194,7 @@ ai.defineFlow(
181194
});
182195

183196
for await (const chunk of stream) {
184-
sendChunk(chunk);
197+
sendChunk(chunk.output);
185198
}
186199

187200
return (await response).output!;
@@ -235,11 +248,11 @@ ai.defineFlow(
235248
inputSchema: z
236249
.string()
237250
.default(
238-
'say that Genkit (G pronounced as J) is an amazing Gen AI library'
251+
'Gemini is amazing. Can say things like: glorg, blub-blub, and ayeeeeee!!!'
239252
),
240253
outputSchema: z.object({ media: z.string() }),
241254
},
242-
async (query) => {
255+
async (prompt) => {
243256
const { media } = await ai.generate({
244257
model: googleAI.model('gemini-2.5-flash-preview-tts'),
245258
config: {
@@ -251,7 +264,7 @@ ai.defineFlow(
251264
},
252265
},
253266
},
254-
prompt: query || 'cheerefully say: Gemini is amazing!',
267+
prompt,
255268
});
256269
if (!media) {
257270
throw new Error('no media returned');

0 commit comments

Comments
 (0)