Compare commits

..

No commits in common. "fb6ec2fc8a2c653322fa4404b57ca23c4d46a0c1" and "c3dac38b6a0bcdbc801a73580953dfd6148c8ccf" have entirely different histories.

1 changed files with 47 additions and 36 deletions

View File

@ -62,55 +62,54 @@ const useSocket = (
'embeddingModelProvider', 'embeddingModelProvider',
); );
const providers = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/models`,
{
headers: {
'Content-Type': 'application/json',
},
},
).then(async (res) => await res.json());
if ( if (
!chatModel || !chatModel ||
!chatModelProvider || !chatModelProvider ||
!embeddingModel || !embeddingModel ||
!embeddingModelProvider !embeddingModelProvider
) { ) {
if (!chatModel || !chatModelProvider) { const providers = await fetch(
const chatModelProviders = providers.chatModelProviders; `${process.env.NEXT_PUBLIC_API_URL}/models`,
{
headers: {
'Content-Type': 'application/json',
},
},
).then(async (res) => await res.json());
chatModelProvider = Object.keys(chatModelProviders)[0]; const chatModelProviders = providers.chatModelProviders;
if (chatModelProvider === 'custom_openai') { chatModelProvider = Object.keys(chatModelProviders)[0];
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');
}
}
if (!embeddingModel || !embeddingModelProvider) { if (chatModelProvider === 'custom_openai') {
const embeddingModelProviders = providers.embeddingModelProviders; 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 ( if (
!embeddingModelProviders || !chatModelProviders ||
Object.keys(embeddingModelProviders).length === 0 Object.keys(chatModelProviders).length === 0
) )
return toast.error('No embedding models available'); return toast.error('No chat models available');
embeddingModelProvider = Object.keys(embeddingModelProviders)[0];
embeddingModel = Object.keys(
embeddingModelProviders[embeddingModelProvider],
)[0];
} }
const embeddingModelProviders = providers.embeddingModelProviders;
if (
!embeddingModelProviders ||
Object.keys(embeddingModelProviders).length === 0
)
return toast.error('No embedding models available');
embeddingModelProvider = Object.keys(embeddingModelProviders)[0];
embeddingModel = Object.keys(
embeddingModelProviders[embeddingModelProvider],
)[0];
localStorage.setItem('chatModel', chatModel!); localStorage.setItem('chatModel', chatModel!);
localStorage.setItem('chatModelProvider', chatModelProvider); localStorage.setItem('chatModelProvider', chatModelProvider);
localStorage.setItem('embeddingModel', embeddingModel!); localStorage.setItem('embeddingModel', embeddingModel!);
@ -119,6 +118,15 @@ const useSocket = (
embeddingModelProvider, embeddingModelProvider,
); );
} else { } else {
const providers = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/models`,
{
headers: {
'Content-Type': 'app lication/json',
},
},
).then(async (res) => await res.json());
const chatModelProviders = providers.chatModelProviders; const chatModelProviders = providers.chatModelProviders;
const embeddingModelProviders = providers.embeddingModelProviders; const embeddingModelProviders = providers.embeddingModelProviders;
@ -187,6 +195,8 @@ const useSocket = (
const timeoutId = setTimeout(() => { const timeoutId = setTimeout(() => {
if (ws.readyState !== 1) { if (ws.readyState !== 1) {
ws.close();
setError(true);
toast.error( toast.error(
'Failed to connect to the server. Please try again later.', 'Failed to connect to the server. Please try again later.',
); );
@ -198,6 +208,7 @@ const useSocket = (
reconnectTimeout.current = 0; reconnectTimeout.current = 0;
reconnectAttempts.current = 0; reconnectAttempts.current = 0;
clearTimeout(timeoutId); clearTimeout(timeoutId);
setError(false);
setIsWSReady(true); setIsWSReady(true);
}; };
@ -220,7 +231,7 @@ const useSocket = (
if (data.type === 'error') { if (data.type === 'error') {
toast.error(data.data); toast.error(data.data);
} }
}) });
setWs(ws); setWs(ws);
}; };