fix: update conditional check last status message (#1951)

* fix: update conditional check last status message

* fix: no new message on failed message

---------

Co-authored-by: Louis <louis@jan.ai>
This commit is contained in:
Faisal Amir 2024-02-07 18:07:12 +07:00 committed by GitHub
parent 5890ade451
commit 9a1b1adc72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 11 deletions

View File

@ -128,10 +128,10 @@ export default function EventHandler({ children }: { children: ReactNode }) {
const thread = threadsRef.current?.find((e) => e.id == message.thread_id)
if (thread) {
const messageContent = message.content[0]?.text.value ?? ''
const messageContent = message.content[0]?.text?.value
const metadata = {
...thread.metadata,
lastMessage: messageContent,
...(messageContent && { lastMessage: messageContent }),
}
updateThread({
@ -151,7 +151,7 @@ export default function EventHandler({ children }: { children: ReactNode }) {
?.addNewMessage(message)
}
},
[updateMessage, updateThreadWaiting, setIsGeneratingResponse]
[updateMessage, updateThreadWaiting, setIsGeneratingResponse, updateThread]
)
useEffect(() => {

View File

@ -70,6 +70,7 @@ export const addNewMessageAtom = atom(
set(chatMessages, newData)
// Update thread last message
if (newMessage.content.length)
set(
updateThreadStateLastMessageAtom,
newMessage.thread_id,
@ -131,6 +132,7 @@ export const updateMessageAtom = atom(
newData[conversationId] = updatedMessages
set(chatMessages, newData)
// Update thread last message
if (text.length)
set(updateThreadStateLastMessageAtom, conversationId, text)
}
}

View File

@ -6,6 +6,7 @@ import {
ThreadAssistantInfo,
ThreadState,
Model,
MessageStatus,
} from '@janhq/core'
import { atom, useAtomValue, useSetAtom } from 'jotai'
@ -20,6 +21,7 @@ import useSetActiveThread from './useSetActiveThread'
import { extensionManager } from '@/extension'
import { getCurrentChatMessagesAtom } from '@/helpers/atoms/ChatMessage.atom'
import {
threadsAtom,
threadStatesAtom,
@ -51,6 +53,7 @@ export const useCreateNewThread = () => {
const setFileUpload = useSetAtom(fileUploadAtom)
const setSelectedModel = useSetAtom(selectedModelAtom)
const setThreadModelParams = useSetAtom(setThreadModelParamsAtom)
const messages = useAtomValue(getCurrentChatMessagesAtom)
const { recommendedModel, downloadedModels } = useRecommendedModel()
@ -63,9 +66,9 @@ export const useCreateNewThread = () => {
const defaultModel = model ?? recommendedModel ?? downloadedModels[0]
// check last thread message, if there empty last message use can not create thread
const lastMessage = threads[0]?.metadata?.lastMessage
const lastMessage = threads[threads.length - 1]?.metadata?.lastMessage
if (!lastMessage && threads.length) {
if (!lastMessage && threads.length && !messages.length) {
return null
}