feat(ws-connector): fix `undefined` chat model

This commit is contained in:
ItzCrazyKns 2024-07-25 20:36:26 +05:30
parent cbce39a5dd
commit 08379fcad5
No known key found for this signature in database
GPG Key ID: 8162927C7CCE3065
1 changed files with 28 additions and 10 deletions

View File

@ -54,13 +54,26 @@ const useSocket = (
).then(async (res) => await res.json());
const chatModelProviders = providers.chatModelProviders;
const embeddingModelProviders = providers.embeddingModelProviders;
chatModelProvider = Object.keys(chatModelProviders)[0];
if (chatModelProvider === 'custom_openai') {
toast.error(
'Seems like you are using the custom OpenAI provider, please open the settings and configure the API key and base URL',
);
setError(true);
return;
} else {
chatModel = Object.keys(chatModelProviders[chatModelProvider])[0];
if (
!chatModelProviders ||
Object.keys(chatModelProviders).length === 0
)
return toast.error('No chat models available');
}
const embeddingModelProviders = providers.embeddingModelProviders;
if (
!embeddingModelProviders ||
@ -68,9 +81,6 @@ const useSocket = (
)
return toast.error('No embedding models available');
chatModelProvider = Object.keys(chatModelProviders)[0];
chatModel = Object.keys(chatModelProviders[chatModelProvider])[0];
embeddingModelProvider = Object.keys(embeddingModelProviders)[0];
embeddingModel = Object.keys(
embeddingModelProviders[embeddingModelProvider],
@ -88,7 +98,7 @@ const useSocket = (
`${process.env.NEXT_PUBLIC_API_URL}/models`,
{
headers: {
'Content-Type': 'application/json',
'Content-Type': 'app lication/json',
},
},
).then(async (res) => await res.json());
@ -106,6 +116,7 @@ const useSocket = (
if (
chatModelProvider &&
chatModelProvider != 'custom_openai' &&
!chatModelProviders[chatModelProvider][chatModel]
) {
chatModel = Object.keys(chatModelProviders[chatModelProvider])[0];
@ -187,6 +198,13 @@ const useSocket = (
console.log('[DEBUG] closed');
};
ws.addEventListener('message', (e) => {
const data = JSON.parse(e.data);
if (data.type === 'error') {
toast.error(data.data);
}
});
setWs(ws);
};