-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrecipeGeneratorFlow.ts
More file actions
37 lines (33 loc) · 1.18 KB
/
recipeGeneratorFlow.ts
File metadata and controls
37 lines (33 loc) · 1.18 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
import { ai } from '../config.js';
import { RecipeInputSchema, RecipeSchema } from '../schemas/recipeSchema.js';
import type { Flow } from '@genkit-ai/core';
// Define a recipe generator flow
/**
* Defines a Genkit flow for generating recipes based on user input.
*
* @param input - An object containing the main ingredient and optional dietary restrictions.
* @returns A generated recipe adhering to the RecipeSchema.
* @throws {Error} If the recipe generation fails.
*/
export const recipeGeneratorFlow: Flow<typeof RecipeInputSchema, typeof RecipeSchema> = ai.defineFlow(
{
name: 'recipeGeneratorFlow',
inputSchema: RecipeInputSchema,
outputSchema: RecipeSchema,
},
async (input) => {
// Create a prompt based on the input
const prompt = `Create a recipe with the following requirements:
Main ingredient: ${input.ingredient}
Dietary restrictions: ${input.dietaryRestrictions ?? 'none'}`;
// Generate structured recipe data using the same schema
const { output } = await ai.generate({
prompt,
output: { schema: RecipeSchema },
});
if (!output) {
throw new Error('Failed to generate recipe');
}
return output;
},
);