fix: create new thread with default assistant

This commit is contained in:
Louis 2024-12-19 11:16:17 +07:00
parent bdcc3ef48c
commit 4cd0e63029
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2
3 changed files with 7 additions and 14 deletions

View File

@ -4,15 +4,9 @@ import { atomWithStorage } from 'jotai/utils'
export const assistantsAtom = atom<Assistant[]>([])
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 })

View File

@ -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)}
</div>
<p className="text-xs font-medium text-gray-400">
{props.created_at && displayDate(props.created_at ?? new Date())}

View File

@ -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) {