From a7f186cc5eb7fe4f0edc530a4695a142a45b9581 Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 27 Dec 2023 15:35:27 +0700 Subject: [PATCH] feat: users should be able to switch models mid-thread (#1226) ## Problem Right now users have to start a new thread to use another model which causes a lot of confusion to our users. fixes #1201 --- web/containers/DropdownListSidebar/index.tsx | 108 ++++++++----------- web/hooks/useSendChatMessage.ts | 5 +- 2 files changed, 51 insertions(+), 62 deletions(-) diff --git a/web/containers/DropdownListSidebar/index.tsx b/web/containers/DropdownListSidebar/index.tsx index 86203ddff..d01adfea9 100644 --- a/web/containers/DropdownListSidebar/index.tsx +++ b/web/containers/DropdownListSidebar/index.tsx @@ -72,69 +72,55 @@ export default function DropdownListSidebar() { if (!activeThread) { return null } - const finishInit = threadStates[activeThread.id].isFinishInit ?? true return ( - - - + + + {downloadedModels.filter((x) => x.id === selected?.id)[0]?.name} + + + +
+ + Local +
+
+ {downloadedModels.length === 0 ? ( +
+

{`Oops, you don't have a model yet.`}

-
- {downloadedModels.length === 0 ? ( -
-

{`Oops, you don't have a model yet.`}

-
- ) : ( - - {downloadedModels.map((x, i) => ( - -
- {x.name} - - {toGigabytes(x.metadata.size)} - -
-
- ))} -
- )} -
-
- -
- - - - - {finishInit && ( - - Start a new thread to change the model - - - )} + ) : ( + + {downloadedModels.map((x, i) => ( + +
+ {x.name} + + {toGigabytes(x.metadata.size)} + +
+
+ ))} +
+ )} +
+
+ +
+ + {selected?.engine === InferenceEngine.openai && (
@@ -154,6 +140,6 @@ export default function DropdownListSidebar() { />
)} - + ) } diff --git a/web/hooks/useSendChatMessage.ts b/web/hooks/useSendChatMessage.ts index 8913104d3..c97f95c7d 100644 --- a/web/hooks/useSendChatMessage.ts +++ b/web/hooks/useSendChatMessage.ts @@ -138,7 +138,10 @@ export default function useSendChatMessage() { const activeThreadState = threadStates[activeThread.id] // if the thread is not initialized, we need to initialize it first - if (!activeThreadState.isFinishInit) { + if ( + !activeThreadState.isFinishInit || + activeThread.assistants[0].model.id !== selectedModel?.id + ) { if (!selectedModel) { toaster({ title: 'Please select a model' }) return