mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-25 17:43:58 +01:00
parent
13ac535504
commit
cb930e3e2c
|
@ -23,26 +23,30 @@ const useSubmit = () => {
|
||||||
message: MessageInterface[]
|
message: MessageInterface[]
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
let data;
|
let data;
|
||||||
if (!apiKey || apiKey.length === 0) {
|
try {
|
||||||
// official endpoint
|
if (!apiKey || apiKey.length === 0) {
|
||||||
if (apiEndpoint === officialAPIEndpoint) {
|
// official endpoint
|
||||||
throw new Error(t('noApiKeyWarning') as string);
|
if (apiEndpoint === officialAPIEndpoint) {
|
||||||
}
|
throw new Error(t('noApiKeyWarning') as string);
|
||||||
|
}
|
||||||
|
|
||||||
// other endpoints
|
// other endpoints
|
||||||
data = await getChatCompletion(
|
data = await getChatCompletion(
|
||||||
useStore.getState().apiEndpoint,
|
useStore.getState().apiEndpoint,
|
||||||
message,
|
message,
|
||||||
_defaultChatConfig
|
_defaultChatConfig
|
||||||
);
|
);
|
||||||
} else if (apiKey) {
|
} else if (apiKey) {
|
||||||
// own apikey
|
// own apikey
|
||||||
data = await getChatCompletion(
|
data = await getChatCompletion(
|
||||||
useStore.getState().apiEndpoint,
|
useStore.getState().apiEndpoint,
|
||||||
message,
|
message,
|
||||||
_defaultChatConfig,
|
_defaultChatConfig,
|
||||||
apiKey
|
apiKey
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
throw new Error(`Error generating title!\n${(error as Error).message}`);
|
||||||
}
|
}
|
||||||
return data.choices[0].message.content;
|
return data.choices[0].message.content;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue