From 4cd0e63029a73e0d54be75fde3f3c3004461c783 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 19 Dec 2024 11:16:17 +0700 Subject: [PATCH] fix: create new thread with default assistant --- web/helpers/atoms/Assistant.atom.ts | 12 +++--------- .../Thread/ThreadCenterPanel/TextMessage/index.tsx | 4 +--- web/screens/Thread/ThreadLeftPanel/index.tsx | 5 +++-- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/web/helpers/atoms/Assistant.atom.ts b/web/helpers/atoms/Assistant.atom.ts index 29da581c34..cb50a0553e 100644 --- a/web/helpers/atoms/Assistant.atom.ts +++ b/web/helpers/atoms/Assistant.atom.ts @@ -4,15 +4,9 @@ import { atomWithStorage } from 'jotai/utils' export const assistantsAtom = atom([]) -export const cachedAssistantAtom = atomWithStorage< - ThreadAssistantInfo | undefined ->('activeAssistant', undefined, undefined, { getOnInit: true }) /** * Get the current active assistant */ -export const activeAssistantAtom = atom( - (get) => get(cachedAssistantAtom) ?? get(assistantsAtom)[0], - (_get, set, newAssistant: ThreadAssistantInfo) => { - set(cachedAssistantAtom, newAssistant) - } -) +export const activeAssistantAtom = atomWithStorage< + ThreadAssistantInfo | undefined +>('activeAssistant', undefined, undefined, { getOnInit: true }) diff --git a/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx b/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx index 52b10b8270..ddd82590bc 100644 --- a/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx +++ b/web/screens/Thread/ThreadCenterPanel/TextMessage/index.tsx @@ -88,9 +88,7 @@ const MessageContainer: React.FC< > {isUser ? props.role - : 'assistant_name' in activeAssistant - ? activeAssistant?.assistant_name - : props.role} + : (activeAssistant?.assistant_name ?? props.role)}

{props.created_at && displayDate(props.created_at ?? new Date())} diff --git a/web/screens/Thread/ThreadLeftPanel/index.tsx b/web/screens/Thread/ThreadLeftPanel/index.tsx index 46763e555c..64a272ca6a 100644 --- a/web/screens/Thread/ThreadLeftPanel/index.tsx +++ b/web/screens/Thread/ThreadLeftPanel/index.tsx @@ -71,7 +71,6 @@ const ThreadLeftPanel = () => { useEffect(() => { if ( threadDataReady && - activeAssistant && assistants.length > 0 && threads.length === 0 && downloadedModels.length > 0 @@ -81,7 +80,9 @@ const ThreadLeftPanel = () => { ) const selectedModel = model[0] || recommendedModel requestCreateNewThread( - { ...assistants[0], ...activeAssistant }, + activeAssistant + ? { ...assistants[0], ...activeAssistant } + : assistants[0], selectedModel ) } else if (threadDataReady && !activeThreadId) {