-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (47 loc) · 1.27 KB
/
index.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import express from "express";
import cors from "cors";
import OpenAI from "openai";
const port = 5000;
const app = express();
const openai = new OpenAI({
apiKey: API_KEY,
});
app.use(
cors({
origin: "*", // Replace with your frontend's domain
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
credentials: true,
allowedHeaders: "Origin,X-Requested-With,Content-Type,Accept,Authorization",
})
);
app.use(express.json());
app.post("/imgUpload", async (req, res) => {
const image = req.query.img;
console.log("Getting into it")
console.log(image);
console.log(req.query);
const response = await openai.chat.completions.create({
model: "gpt-4-vision-preview",
messages: [
{
role: "user",
content: [
{
type: "text",
text: "A food item is shown in the image. Find the name of the food item in the image in one word",
},
{
type: "image_url",
image_url: {
url: image,
},
},
],
},
],
});
console.log("Completed")
console.log(response)
res.send(response.choices[0].message.content);
});
app.listen(port, () => console.log(`Server running on ${port}`));