Compare commits

...

2 Commits

Author SHA1 Message Date
projectmoon fb6ec2fc8a Merge remote-tracking branch 'origin/master' into ollama-auth 2024-08-07 12:32:08 +02:00
ItzCrazyKns 9c1936ec2c
feat(chat-window): lint & beautify 2024-08-04 18:14:46 +05:30
1 changed files with 37 additions and 48 deletions

View File

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