From f0a0156c228a29e11ac50940cadbb5190357fd90 Mon Sep 17 00:00:00 2001 From: Jing Hua <59118459+ztjhz@users.noreply.github.com> Date: Fri, 5 May 2023 21:31:54 +0800 Subject: [PATCH] delete unused files delete customApi.ts --- src/api/customApi.ts | 67 -------------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 src/api/customApi.ts diff --git a/src/api/customApi.ts b/src/api/customApi.ts deleted file mode 100644 index 65fcccf..0000000 --- a/src/api/customApi.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { ConfigInterface, MessageInterface } from '@type/chat'; - -export const endpoint = 'https://api.openai.com/v1/chat/completions'; - -export const validateApiKey = async (apiKey: string) => { - try { - const response = await fetch(endpoint, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${apiKey}`, - }, - }); - const data = await response.json(); - - if (response.status === 401) return false; - else if (response.status === 400) return true; - } catch (error) { - console.error('Error:', error); - return false; - } -}; - -export const getChatCompletion = async ( - apiKey: string, - messages: MessageInterface[], - config: ConfigInterface -) => { - const response = await fetch(endpoint, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${apiKey}`, - }, - body: JSON.stringify({ - messages, - ...config, - }), - }); - if (!response.ok) throw new Error(await response.text()); - - const data = await response.json(); - return data; -}; - -export const getChatCompletionStream = async ( - apiKey: string, - messages: MessageInterface[], - config: ConfigInterface -) => { - const response = await fetch(endpoint, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${apiKey}`, - }, - body: JSON.stringify({ - messages, - ...config, - stream: true, - }), - }); - if (!response.ok) throw new Error(await response.text()); - - const stream = response.body; - return stream; -};