mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-25 19:43:59 +01:00
chore: remove unused file (#272)
* Delete freeApi.ts --------- Co-authored-by: Jing Hua <59118459+ztjhz@users.noreply.github.com>
This commit is contained in:
parent
d2d14876c1
commit
13b272bfd9
|
@ -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;
|
|
||||||
};
|
|
Loading…
Reference in a new issue