-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path10-vision.ts
More file actions
27 lines (22 loc) · 785 Bytes
/
10-vision.ts
File metadata and controls
27 lines (22 loc) · 785 Bytes
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
// This example demonstrates how to use the OpenAI API to analyze pictures.
import process from "node:process";
import fs from "node:fs";
import { OpenAI } from "openai";
// Load an image and convert it to base64
const image = fs.readFileSync("./data/image.jpg");
const base64 = Buffer.from(image).toString("base64");
const openai = new OpenAI({
baseURL: "https://models.inference.ai.azure.com",
apiKey: process.env.GITHUB_TOKEN,
});
const chatCompletion = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [{
role: "user",
content: [
{ type: "text", text: "Describe the image" },
{ type: "image_url", image_url: { url: `data:image/jpeg;base64,${base64}` } }
]
}],
});
console.log(chatCompletion.choices[0].message.content);