fix: show generate response on message send (#1895)
* fix: show generate response on message send * chore: typo
This commit is contained in:
parent
5ce2e422f8
commit
9e4658f5b2
@ -61,9 +61,8 @@ export default function EventHandler({ children }: { children: ReactNode }) {
|
|||||||
const onNewMessageResponse = useCallback(
|
const onNewMessageResponse = useCallback(
|
||||||
(message: ThreadMessage) => {
|
(message: ThreadMessage) => {
|
||||||
addNewMessage(message)
|
addNewMessage(message)
|
||||||
setIsGeneratingResponse(false)
|
|
||||||
},
|
},
|
||||||
[addNewMessage, setIsGeneratingResponse]
|
[addNewMessage]
|
||||||
)
|
)
|
||||||
|
|
||||||
const onModelReady = useCallback(
|
const onModelReady = useCallback(
|
||||||
@ -114,8 +113,10 @@ export default function EventHandler({ children }: { children: ReactNode }) {
|
|||||||
message.status
|
message.status
|
||||||
)
|
)
|
||||||
if (message.status === MessageStatus.Pending) {
|
if (message.status === MessageStatus.Pending) {
|
||||||
if (message.content.length)
|
if (message.content.length) {
|
||||||
updateThreadWaiting(message.thread_id, false)
|
updateThreadWaiting(message.thread_id, false)
|
||||||
|
setIsGeneratingResponse(false)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Mark the thread as not waiting for response
|
// Mark the thread as not waiting for response
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import {
|
|||||||
ThreadState,
|
ThreadState,
|
||||||
Model,
|
Model,
|
||||||
} from '@janhq/core'
|
} from '@janhq/core'
|
||||||
import { atom, useAtomValue, useSetAtom } from 'jotai'
|
import { atom, useSetAtom } from 'jotai'
|
||||||
|
|
||||||
import { selectedModelAtom } from '@/containers/DropdownListSidebar'
|
import { selectedModelAtom } from '@/containers/DropdownListSidebar'
|
||||||
import { fileUploadAtom } from '@/containers/Providers/Jotai'
|
import { fileUploadAtom } from '@/containers/Providers/Jotai'
|
||||||
|
|||||||
@ -39,6 +39,7 @@ import {
|
|||||||
activeThreadAtom,
|
activeThreadAtom,
|
||||||
engineParamsUpdateAtom,
|
engineParamsUpdateAtom,
|
||||||
getActiveThreadModelParamsAtom,
|
getActiveThreadModelParamsAtom,
|
||||||
|
isGeneratingResponseAtom,
|
||||||
updateThreadAtom,
|
updateThreadAtom,
|
||||||
updateThreadWaitingForResponseAtom,
|
updateThreadWaitingForResponseAtom,
|
||||||
} from '@/helpers/atoms/Thread.atom'
|
} from '@/helpers/atoms/Thread.atom'
|
||||||
@ -57,7 +58,7 @@ export default function useSendChatMessage() {
|
|||||||
const { activeModel } = useActiveModel()
|
const { activeModel } = useActiveModel()
|
||||||
const selectedModel = useAtomValue(selectedModelAtom)
|
const selectedModel = useAtomValue(selectedModelAtom)
|
||||||
const { startModel } = useActiveModel()
|
const { startModel } = useActiveModel()
|
||||||
const [queuedMessage, setQueuedMessage] = useAtom(queuedMessageAtom)
|
const setQueuedMessage = useSetAtom(queuedMessageAtom)
|
||||||
const loadModelFailed = useAtomValue(loadModelErrorAtom)
|
const loadModelFailed = useAtomValue(loadModelErrorAtom)
|
||||||
|
|
||||||
const modelRef = useRef<Model | undefined>()
|
const modelRef = useRef<Model | undefined>()
|
||||||
@ -68,6 +69,7 @@ export default function useSendChatMessage() {
|
|||||||
const setEngineParamsUpdate = useSetAtom(engineParamsUpdateAtom)
|
const setEngineParamsUpdate = useSetAtom(engineParamsUpdateAtom)
|
||||||
const setReloadModel = useSetAtom(reloadModelAtom)
|
const setReloadModel = useSetAtom(reloadModelAtom)
|
||||||
const [fileUpload, setFileUpload] = useAtom(fileUploadAtom)
|
const [fileUpload, setFileUpload] = useAtom(fileUploadAtom)
|
||||||
|
const setIsGeneratingResponse = useSetAtom(isGeneratingResponseAtom)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
modelRef.current = activeModel
|
modelRef.current = activeModel
|
||||||
@ -82,6 +84,7 @@ export default function useSendChatMessage() {
|
|||||||
console.error('No active thread')
|
console.error('No active thread')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
setIsGeneratingResponse(true)
|
||||||
updateThreadWaiting(activeThread.id, true)
|
updateThreadWaiting(activeThread.id, true)
|
||||||
const messages: ChatCompletionMessage[] = [
|
const messages: ChatCompletionMessage[] = [
|
||||||
activeThread.assistants[0]?.instructions,
|
activeThread.assistants[0]?.instructions,
|
||||||
@ -132,6 +135,7 @@ export default function useSendChatMessage() {
|
|||||||
console.error('No active thread')
|
console.error('No active thread')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
setIsGeneratingResponse(true)
|
||||||
|
|
||||||
if (engineParamsUpdate) setReloadModel(true)
|
if (engineParamsUpdate) setReloadModel(true)
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { useEffect } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Modal,
|
Modal,
|
||||||
@ -49,17 +49,19 @@ export default function ThreadList() {
|
|||||||
const activeThread = useAtomValue(activeThreadAtom)
|
const activeThread = useAtomValue(activeThreadAtom)
|
||||||
const { deleteThread, cleanThread } = useDeleteThread()
|
const { deleteThread, cleanThread } = useDeleteThread()
|
||||||
const { downloadedModels } = useGetDownloadedModels()
|
const { downloadedModels } = useGetDownloadedModels()
|
||||||
|
const [isThreadsReady, setIsThreadsReady] = useState(false)
|
||||||
|
|
||||||
const { activeThreadId, setActiveThread: onThreadClick } =
|
const { activeThreadId, setActiveThread: onThreadClick } =
|
||||||
useSetActiveThread()
|
useSetActiveThread()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getThreads()
|
getThreads().then(() => setIsThreadsReady(true))
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
|
isThreadsReady &&
|
||||||
downloadedModels.length !== 0 &&
|
downloadedModels.length !== 0 &&
|
||||||
threads.length === 0 &&
|
threads.length === 0 &&
|
||||||
assistants.length !== 0 &&
|
assistants.length !== 0 &&
|
||||||
@ -68,7 +70,7 @@ export default function ThreadList() {
|
|||||||
requestCreateNewThread(assistants[0])
|
requestCreateNewThread(assistants[0])
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [assistants, threads, downloadedModels, activeThread])
|
}, [assistants, threads, downloadedModels, activeThread, isThreadsReady])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="px-3 py-4">
|
<div className="px-3 py-4">
|
||||||
|
|||||||
@ -66,7 +66,7 @@ const ModalConfirmReset = () => {
|
|||||||
Keep the current app data location
|
Keep the current app data location
|
||||||
</label>
|
</label>
|
||||||
<p className="mt-2 leading-relaxed">
|
<p className="mt-2 leading-relaxed">
|
||||||
Otherwise it will reset back to its original location at:
|
Otherwise it will reset back to its original location at:{' '}
|
||||||
{/* TODO should be from system */}
|
{/* TODO should be from system */}
|
||||||
<span className="font-medium">{defaultJanDataFolder}</span>
|
<span className="font-medium">{defaultJanDataFolder}</span>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user