MCPcopy Create free account
hub / github.com/Nutlope/picMenu / POST

Function POST

app/api/parseMenu/route.ts:17–108  ·  view source on GitHub ↗
(request: Request)

Source from the content-addressed store, hash-verified

15const together = new Together(options);
16
17export async function POST(request: Request) {
18 const { menuUrl } = await request.json();
19
20 console.log({ menuUrl });
21
22 if (!menuUrl) {
23 return Response.json({ error: "No menu URL provided" }, { status: 400 });
24 }
25
26 const systemPrompt = `You are given an image of a menu. Your job is to take each item in the menu and convert it into the following JSON format:
27
28[{"name": "name of menu item", "price": "price of the menu item", "description": "description of menu item"}, ...]
29
30 Please make sure to include all items in the menu and include a price (if it exists) & a description (if it exists). ALSO PLEASE ONLY RETURN JSON. IT'S VERY IMPORTANT FOR MY JOB THAT YOU ONLY RETURN JSON.
31 `;
32
33 const output = await together.chat.completions.create({
34 model: "meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo",
35 messages: [
36 {
37 role: "user",
38 content: [
39 { type: "text", text: systemPrompt },
40 {
41 type: "image_url",
42 image_url: {
43 url: menuUrl,
44 },
45 },
46 ],
47 },
48 ],
49 });
50
51 const menuItems = output?.choices[0]?.message?.content;
52
53 // Defining the schema we want our data in
54 const menuSchema = z.array(
55 z.object({
56 name: z.string().describe("The name of the menu item"),
57 price: z.string().describe("The price of the menu item"),
58 description: z
59 .string()
60 .describe(
61 "The description of the menu item. If this doesn't exist, please write a short one sentence description."
62 ),
63 })
64 );
65 const jsonSchema = toJSONSchema(menuSchema);
66
67 const extract = await together.chat.completions.create({
68 messages: [
69 {
70 role: "system",
71 content:
72 "The following is a list of items from a menu. Only answer in JSON.",
73 },
74 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected