-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweatherFlow.ts
More file actions
25 lines (24 loc) · 868 Bytes
/
weatherFlow.ts
File metadata and controls
25 lines (24 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { ai } from '../config.js';
import { z } from 'genkit';
import { weatherTool } from '../tools/weatherTool.js';
export const weatherFlow = ai.defineFlow(
{
name: 'weatherFlow',
inputSchema: z.string(),
outputSchema: z.string(),
},
async (location) => {
const weather = await weatherTool({ location });
if (typeof weather === 'string') {
return `I looked up the weather in ${location} for you. Here it is: ${weather}`;
}
const parts = [
`${weather.location}: ${weather.temperature}${weather.unit}`,
`(feels like ${weather.feelsLike}${weather.unit})`,
`humidity ${weather.humidity}%`,
`wind ${weather.windSpeed} m/s` + (weather.windGust > 0 ? ` (gusts ${weather.windGust} m/s)` : ''),
weather.conditions,
];
return `I looked up the weather in ${location}. ${parts.join(', ')}`;
}
);