-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvision.js
31 lines (29 loc) · 990 Bytes
/
vision.js
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
import OpenAI from "openai";
const openai = new OpenAI();
const extractBeerNamesFromImage = async (base64Image) => {
const response = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{
role: "user",
content: [
{
type: "text",
text: "Can you extract the names of the beers present in the uploaded image and return only the json array on one line ?"
},
{
type: "image_url",
image_url: {
url: base64Image
},
},
],
},
]
});
return JSON.parse(response.choices[0].message.content.slice(7, -3));
}
export default async (req, res) => {
const beerNames = await extractBeerNamesFromImage(req.body.image);
res.json(beerNames);
}