we're actually calling openai

This commit is contained in:
Kyle Corbitt
2023-06-22 17:57:21 -07:00
parent 0fa3af4e9f
commit a31c112745
14 changed files with 271 additions and 30 deletions

View File

@@ -0,0 +1,19 @@
import { JSONSerializable } from "./fillTemplate";
export async function getChatCompletion(payload: JSONSerializable, apiKey: string) {
const response = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify(payload),
});
if (!response.ok) {
throw new Error(`OpenAI API request failed with status ${response.status}`);
}
const data = (await response.json()) as JSONSerializable;
return data;
}