how i extract recipes
0
example.ts
1 chat({
2 content: [
3 {
4 type: "image",
5 base64: base64Data,
6 mimeType: mediaTypeMap[imageType] || "image/png",
7 },
8 {
9 type: "text",
10 content: dedent`
11 Analyze this screenshot of a recipe webpage and extract recipe information.
12
13 - Extract all available information visible in the screenshot.
14 - If something is not found, use null for optional fields.
15 - For ingredients, parse quantities and units.
16 - Always provide heuristicAmount + heuristicUnit when possible, and also provide measuredAmount + measuredUnit when possible.
17 - (e.g., "2 cups flour" -> measuredAmount: 250, measuredUnit: 'g', heuristicAmount: 2, heuristicUnit: 'cups', name: "flour")
18 - Do use the same values for heuristicAmount and measuredAmount.
19 - In most cases a recipe will have heuristicAmount and we should guess a measuredAmount
20 - If the ingredient name contains some preparation (i.e melted, beaten, etc.), remove it from the name and add it to the notes. (e.g., "2 cups melted butter" -> measuredAmount: 250, measuredUnit: 'g', notes: "melted", name: "butter")
21 - For "group": If ingredients are organized into groups (e.g., "For the sauce:", "For the pasta:", "For the marinade:"), include the group name in the "group" field. If ingredients are not grouped, set it to null.
22 - Represent tablespoon as tbsp and teaspoon as tsp.
23 - Convert all times to minutes and output numbers (not strings) for numeric fields.
24 - Generate a description if one is not provided.
25 - For "source": Try to identify the source name. Use null if unknown.
26 - For "url": Always include the source URL (${url}) here.
27 `,
28 },
29 ],
30 outputSchema: UrlRecipeExtractionSchema,
31 maxTokens: 4096,
32 adapter,
33 modelName,
34 });