-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebResearchFlow.ts
More file actions
24 lines (23 loc) · 925 Bytes
/
webResearchFlow.ts
File metadata and controls
24 lines (23 loc) · 925 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
import type { z } from 'zod';
import type { Flow } from '@genkit-ai/core';
import { ai } from '../config.js';
import { UserFacingError } from '../errors/UserFacingError.js';
import { WebResearchInputSchema, WebResearchOutputSchema } from '../schemas/index.js';
export const webResearchFlow: Flow<typeof WebResearchInputSchema, typeof WebResearchOutputSchema> = ai.defineFlow(
{
name: 'webResearchFlow',
inputSchema: WebResearchInputSchema,
outputSchema: WebResearchOutputSchema,
},
async (input: z.infer<typeof WebResearchInputSchema>) => {
const webPrompt = ai.prompt('web_research');
const result = await webPrompt(input);
const parsed = WebResearchOutputSchema.safeParse(result.output);
if (!parsed.success) {
throw new UserFacingError('Schema validation failed for webResearchFlow output', {
details: parsed.error.flatten(),
});
}
return parsed.data;
}
);