Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): better handling the ui in case of errors connecting with bac… #543

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions ui/components/ChatWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { toast } from 'sonner';
import { useSearchParams } from 'next/navigation';
import { getSuggestions } from '@/lib/actions';
import Error from 'next/error';
import axios from 'axios';

export type Message = {
messageId: string;
Expand Down Expand Up @@ -52,14 +53,17 @@ const useSocket = (
? localStorage.getItem('openAIApiKey')
: null;

const providers = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/models`,
{
headers: {
'Content-Type': 'application/json',
},
},
).then(async (res) => await res.json());
let providers;

try {
providers = await axios.get(
`${process.env.NEXT_PUBLIC_API_URL}/models`,
);
providers = providers.data;
} catch (e) {
setError(true);
return;
}

if (
!chatModel ||
Expand Down Expand Up @@ -113,10 +117,11 @@ const useSocket = (
embeddingModelProvider,
);
} else {
const chatModelProviders = providers.chatModelProviders;
const embeddingModelProviders = providers.embeddingModelProviders;
const chatModelProviders = providers?.chatModelProviders;
const embeddingModelProviders = providers?.embeddingModelProviders;

if (
chatModelProviders &&
Object.keys(chatModelProviders).length > 0 &&
(((!openAIBaseURL || !openAIPIKey) &&
chatModelProvider === 'custom_openai') ||
Expand Down Expand Up @@ -144,6 +149,7 @@ const useSocket = (

if (
chatModelProvider &&
chatModelProviders &&
(!openAIBaseURL || !openAIPIKey) &&
!chatModelProviders[chatModelProvider][chatModel]
) {
Expand All @@ -158,6 +164,7 @@ const useSocket = (
}

if (
embeddingModelProviders &&
Object.keys(embeddingModelProviders).length > 0 &&
!embeddingModelProviders[embeddingModelProvider]
) {
Expand All @@ -170,6 +177,7 @@ const useSocket = (

if (
embeddingModelProvider &&
embeddingModelProviders &&
!embeddingModelProviders[embeddingModelProvider][embeddingModel]
) {
embeddingModel = Object.keys(
Expand Down