feat(chat-window): unselect unavailable model

This commit is contained in:
ItzCrazyKns 2024-07-09 16:21:45 +05:30
parent 8539ce82ad
commit 27e6f5b9e1
No known key found for this signature in database
GPG Key ID: 8162927C7CCE3065
1 changed files with 49 additions and 0 deletions

View File

@ -83,6 +83,55 @@ const useSocket = (
'embeddingModelProvider', 'embeddingModelProvider',
embeddingModelProvider, embeddingModelProvider,
); );
} else {
const providers = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/models`,
{
headers: {
'Content-Type': 'application/json',
},
},
).then(async (res) => await res.json());
const chatModelProviders = providers.chatModelProviders;
const embeddingModelProviders = providers.embeddingModelProviders;
if (
Object.keys(chatModelProviders).length > 0 &&
!chatModelProviders[chatModelProvider]
) {
chatModelProvider = Object.keys(chatModelProviders)[0];
localStorage.setItem('chatModelProvider', chatModelProvider);
}
if (
chatModelProvider &&
!chatModelProviders[chatModelProvider][chatModel]
) {
chatModel = Object.keys(chatModelProviders[chatModelProvider])[0];
localStorage.setItem('chatModel', chatModel);
}
if (
Object.keys(embeddingModelProviders).length > 0 &&
!embeddingModelProviders[embeddingModelProvider]
) {
embeddingModelProvider = Object.keys(embeddingModelProviders)[0];
localStorage.setItem(
'embeddingModelProvider',
embeddingModelProvider,
);
}
if (
embeddingModelProvider &&
!embeddingModelProviders[embeddingModelProvider][embeddingModel]
) {
embeddingModel = Object.keys(
embeddingModelProviders[embeddingModelProvider],
)[0];
localStorage.setItem('embeddingModel', embeddingModel);
}
} }
const wsURL = new URL(url); const wsURL = new URL(url);