From 08379fcad5a9cb40b66f48f3078aebb16c5fa6e5 Mon Sep 17 00:00:00 2001 From: ItzCrazyKns Date: Thu, 25 Jul 2024 20:36:26 +0530 Subject: [PATCH] feat(ws-connector): fix `undefined` chat model --- ui/components/ChatWindow.tsx | 38 ++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index f2c89a3..ea9a93d 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -54,13 +54,26 @@ 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 || @@ -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); };