feat: url scraper to recipe
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import OpenAI from "https://deno.land/x/openai@v4.52.0/mod.ts";
|
||||
import OpenAI from "https://deno.land/x/openai@v4.69.0/mod.ts";
|
||||
import { zodResponseFormat } from "https://deno.land/x/openai@v4.69.0/helpers/zod.ts";
|
||||
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";
|
||||
|
||||
const openAI = OPENAI_API_KEY && new OpenAI({ apiKey: OPENAI_API_KEY });
|
||||
|
||||
@@ -208,3 +210,21 @@ export async function createTags(content: string) {
|
||||
|
||||
return extractListFromResponse(res).map((v) => v.replaceAll(" ", "-"));
|
||||
}
|
||||
|
||||
export async function extractRecipe(content: string) {
|
||||
if (!openAI) return;
|
||||
const completion = await openAI.beta.chat.completions.parse({
|
||||
model: "gpt-4o-2024-08-06",
|
||||
temperature: 0.1,
|
||||
messages: [
|
||||
{
|
||||
role: "system",
|
||||
content: "Extract the recipe information from the provided markdown.",
|
||||
},
|
||||
{ role: "user", content },
|
||||
],
|
||||
response_format: zodResponseFormat(recipeSchema, "recipe-v2"),
|
||||
});
|
||||
|
||||
return recipeSchema.parse(completion.choices[0].message.parsed);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user