fix: deleting threads manually breaks model settings and document upload (#2456)

* fix: blank model settings and rag does not work

* fix: fallback support fro previous broken threads
This commit is contained in:
Louis 2024-03-22 13:56:46 +07:00 committed by GitHub
parent 8303f74f58
commit 5edc24d8e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 2 deletions

View File

@ -249,6 +249,15 @@ export default function useSendChatMessage() {
let modelRequest = let modelRequest =
selectedModelRef?.current ?? activeThreadRef.current.assistants[0].model selectedModelRef?.current ?? activeThreadRef.current.assistants[0].model
// Fallback support for previous broken threads
if (activeThreadRef.current?.assistants[0]?.model?.id === '*') {
activeThreadRef.current.assistants[0].model = {
id: modelRequest.id,
settings: modelRequest.settings,
parameters: modelRequest.parameters,
}
}
if (runtimeParams.stream == null) { if (runtimeParams.stream == null) {
runtimeParams.stream = true runtimeParams.stream = true
} }

View File

@ -9,6 +9,7 @@ import { GalleryHorizontalEndIcon, MoreVerticalIcon } from 'lucide-react'
import { twMerge } from 'tailwind-merge' import { twMerge } from 'tailwind-merge'
import { useCreateNewThread } from '@/hooks/useCreateNewThread' import { useCreateNewThread } from '@/hooks/useCreateNewThread'
import useRecommendedModel from '@/hooks/useRecommendedModel'
import useSetActiveThread from '@/hooks/useSetActiveThread' import useSetActiveThread from '@/hooks/useSetActiveThread'
import { displayDate } from '@/utils/datetime' import { displayDate } from '@/utils/datetime'
@ -35,6 +36,7 @@ export default function ThreadList() {
const threadDataReady = useAtomValue(threadDataReadyAtom) const threadDataReady = useAtomValue(threadDataReadyAtom)
const { requestCreateNewThread } = useCreateNewThread() const { requestCreateNewThread } = useCreateNewThread()
const setEditMessage = useSetAtom(editMessageAtom) const setEditMessage = useSetAtom(editMessageAtom)
const { recommendedModel, downloadedModels } = useRecommendedModel()
const onThreadClick = useCallback( const onThreadClick = useCallback(
(thread: Thread) => { (thread: Thread) => {
@ -50,8 +52,14 @@ export default function ThreadList() {
* and there are no threads available * and there are no threads available
*/ */
useEffect(() => { useEffect(() => {
if (threadDataReady && assistants.length > 0 && threads.length === 0) { if (
requestCreateNewThread(assistants[0]) threadDataReady &&
assistants.length > 0 &&
threads.length === 0 &&
(recommendedModel || downloadedModels[0])
) {
const model = recommendedModel || downloadedModels[0]
requestCreateNewThread(assistants[0], model)
} else if (threadDataReady && !activeThreadId) { } else if (threadDataReady && !activeThreadId) {
setActiveThread(threads[0]) setActiveThread(threads[0])
} }
@ -62,6 +70,8 @@ export default function ThreadList() {
requestCreateNewThread, requestCreateNewThread,
activeThreadId, activeThreadId,
setActiveThread, setActiveThread,
recommendedModel,
downloadedModels,
]) ])
return ( return (