From 13b272bfd9b2ad4e303782ad7daa9e7e760cceca Mon Sep 17 00:00:00 2001 From: Landry Simo <86841267+LandPix200@users.noreply.github.com> Date: Thu, 4 May 2023 16:13:19 +0100 Subject: [PATCH] chore: remove unused file (#272) * Delete freeApi.ts --------- Co-authored-by: Jing Hua <59118459+ztjhz@users.noreply.github.com> --- src/api/freeApi.ts | 57 ---------------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 src/api/freeApi.ts diff --git a/src/api/freeApi.ts b/src/api/freeApi.ts deleted file mode 100644 index d8e9114..0000000 --- a/src/api/freeApi.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { ConfigInterface, MessageInterface } from '@type/chat'; - -export const getChatCompletion = async ( - endpoint: string, - messages: MessageInterface[], - config: ConfigInterface -) => { - const response = await fetch(endpoint, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - 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 ( - endpoint: string, - messages: MessageInterface[], - config: ConfigInterface -) => { - const response = await fetch(endpoint, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - messages, - ...config, - stream: true, - }), - }); - if (response.status === 404 || response.status === 405) - throw new Error( - 'Message from Better ChatGPT:\nInvalid API endpoint! We recommend you to check your free API endpoint.' - ); - - if (response.status === 429 || !response.ok) { - const text = await response.text(); - let error = text; - if (text.includes('insufficient_quota')) { - error += - '\nMessage from Better ChatGPT:\nWe recommend changing your API endpoint or API key'; - } - throw new Error(error); - } - - const stream = response.body; - return stream; -};