we're actually calling openai
This commit is contained in:
19
src/server/utils/openai.ts
Normal file
19
src/server/utils/openai.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user