refactor: simplify parse ingredients code

This commit is contained in:
2025-01-19 19:22:19 +01:00
parent f106460502
commit 78e94ccf82
14 changed files with 201 additions and 137 deletions

View File

@@ -3,7 +3,7 @@ import { zodResponseFormat } from "https://deno.land/x/openai@v4.69.0/helpers/zo
import { OPENAI_API_KEY } from "@lib/env.ts";
import { hashString } from "@lib/helpers.ts";
import { createCache } from "@lib/cache.ts";
import recipeSchema from "@lib/recipeSchema.ts";
import recipeSchema, { recipeResponseSchema } from "@lib/recipeSchema.ts";
const openAI = OPENAI_API_KEY && new OpenAI({ apiKey: OPENAI_API_KEY });
@@ -223,7 +223,7 @@ export async function extractRecipe(content: string) {
},
{ role: "user", content },
],
response_format: zodResponseFormat(recipeSchema, "recipe-v2"),
response_format: zodResponseFormat(recipeResponseSchema, "recipe-v2"),
});
return recipeSchema.parse(completion.choices[0].message.parsed);