1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import process from "node:process";
export const chat = async (
prompt: string | object = "Hello world",
options = {},
) => {
// Initialize OpenAI API stub
const { OpenAI } = await import(
"https://esm.sh/openai"
);
const openai = new OpenAI();
const messages = typeof prompt === "string"
? [{ role: "user", content: prompt }]
: prompt;
const completion = await openai.chat.completions.create({
messages: messages,
model: "gpt-3.5-turbo",
...options,
});
return completion.choices[0];
};