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; -};