import OpenAI from "openai";
// citations is a Seltz extension, so it is not on the OpenAI response type.
// It is present when the search returned URL-bearing sources.
type SeltzCompletion = OpenAI.Chat.ChatCompletion & {
citations?: { url: string }[];
};
const client = new OpenAI({
baseURL: "https://api.seltz.ai/v1",
apiKey: process.env.SELTZ_API_KEY,
});
const completion: SeltzCompletion = await client.chat.completions.create({
model: "seltz-base",
messages: [
{ role: "user", content: "Who is going to be Apple's next CEO?" },
],
});
console.log(completion.choices[0].message.content);
for (const citation of completion.citations ?? []) {
console.log(citation.url);
}