1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { OpenAI } from "https://deno.land/x/openai@v4.54.0/mod.ts";
const apiKey = Deno.env.get("OPENAI_API_KEY");
const openai = new OpenAI({ apiKey });
export async function askAI(msg: string) {
const cfg = {
messages: [{ role: "user", content: msg }],
model: "gpt-4o-mini",
max_tokens: 3000,
} satisfies OpenAI.ChatCompletionCreateParamsNonStreaming;
const chat = await openai.chat.completions.create(cfg);
return chat.choices?.[0].message.content;
}