fix: thread error handling

This commit is contained in:
Louis 2024-12-20 16:34:54 +07:00
parent 9603d36a1f
commit 11f4f20120
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2
2 changed files with 10 additions and 7 deletions

View File

@ -302,15 +302,10 @@ export default function ModelHandler() {
const generateThreadTitle = (message: ThreadMessage, thread: Thread) => { const generateThreadTitle = (message: ThreadMessage, thread: Thread) => {
// If this is the first ever prompt in the thread // If this is the first ever prompt in the thread
if ( if ((thread.title ?? thread.metadata?.title)?.trim() !== defaultThreadTitle)
(thread.title ?? thread.metadata?.title)?.trim() !== defaultThreadTitle
) {
return return
}
if (!activeModelRef.current) { if (!activeModelRef.current) return
return
}
// Check model engine; we don't want to generate a title when it's not a local engine. remote model using first promp // Check model engine; we don't want to generate a title when it's not a local engine. remote model using first promp
if (!isLocalEngine(activeModelRef.current?.engine as InferenceEngine)) { if (!isLocalEngine(activeModelRef.current?.engine as InferenceEngine)) {
@ -332,6 +327,7 @@ export default function ModelHandler() {
...updatedThread, ...updatedThread,
}) })
}) })
.catch(console.error)
} }
// This is the first time message comes in on a new thread // This is the first time message comes in on a new thread

View File

@ -37,9 +37,16 @@ export default function useDeleteThread() {
async (threadId: string) => { async (threadId: string) => {
const thread = threads.find((c) => c.id === threadId) const thread = threads.find((c) => c.id === threadId)
if (!thread) return if (!thread) return
const availableThreads = threads.filter((c) => c.id !== threadId)
setThreads(availableThreads)
// delete the thread state
deleteThreadState(threadId)
const assistantInfo = await extensionManager const assistantInfo = await extensionManager
.get<ConversationalExtension>(ExtensionTypeEnum.Conversational) .get<ConversationalExtension>(ExtensionTypeEnum.Conversational)
?.getThreadAssistant(thread.id) ?.getThreadAssistant(thread.id)
.catch(console.error)
if (!assistantInfo) return if (!assistantInfo) return
const model = models.find((c) => c.id === assistantInfo?.model?.id) const model = models.find((c) => c.id === assistantInfo?.model?.id)