refac: floating buttons

This commit is contained in:
Timothy Jaeryang Baek
2024-12-20 14:38:15 -08:00
parent d6f0c77c34
commit 37ce88e744
6 changed files with 386 additions and 121 deletions
+32
View File
@@ -273,6 +273,38 @@ export const verifyOpenAIConnection = async (
return res;
};
export const chatCompletion = async (
token: string = '',
body: object,
url: string = OPENAI_API_BASE_URL
): Promise<[Response | null, AbortController]> => {
const controller = new AbortController();
let error = null;
const res = await fetch(`${url}/chat/completions`, {
signal: controller.signal,
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
}).catch((err) => {
console.log(err);
error = err;
return null;
});
if (error) {
throw error;
}
return [res, controller];
};
export const generateOpenAIChatCompletion = async (
token: string = '',
body: object,