chore: remove unused file (#272)

* Delete freeApi.ts

---------

Co-authored-by: Jing Hua <59118459+ztjhz@users.noreply.github.com>
This commit is contained in:
Landry Simo 2023-05-04 16:13:19 +01:00 committed by GitHub
parent d2d14876c1
commit 13b272bfd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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