Skip to content

Commit

Permalink
feat(ws-connector): fix undefined chat model
Browse files Browse the repository at this point in the history
  • Loading branch information
ItzCrazyKns committed Jul 25, 2024
1 parent cbce39a commit 08379fc
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions ui/components/ChatWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,33 @@ const useSocket = (
).then(async (res) => await res.json());

const chatModelProviders = providers.chatModelProviders;
const embeddingModelProviders = providers.embeddingModelProviders;

if (
!chatModelProviders ||
Object.keys(chatModelProviders).length === 0
)
return toast.error('No chat models available');
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 ||
Object.keys(embeddingModelProviders).length === 0
)
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],
Expand All @@ -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());
Expand All @@ -106,6 +116,7 @@ const useSocket = (

if (
chatModelProvider &&
chatModelProvider != 'custom_openai' &&
!chatModelProviders[chatModelProvider][chatModel]
) {
chatModel = Object.keys(chatModelProviders[chatModelProvider])[0];
Expand Down Expand Up @@ -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);
};

Expand Down

0 comments on commit 08379fc

Please sign in to comment.