* fix: reduce the number of api call Signed-off-by: James <james@jan.ai> * fix: download progress Signed-off-by: James <james@jan.ai> * chore: save blob * fix: server boot up * fix: download state not updating Signed-off-by: James <james@jan.ai> * fix: copy assets * Add Dockerfile CPU for Jan Server and Jan Web * Add Dockerfile GPU for Jan Server and Jan Web * feat: S3 adapter * Update check find count from ./pre-install and correct copy:asserts command * server add bundleDependencies @janhq/core * server add bundleDependencies @janhq/core * fix: update success/failed download state (#1945) * fix: update success/failed download state Signed-off-by: James <james@jan.ai> * fix: download model progress and state handling for both Desktop and Web --------- Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai> Co-authored-by: Louis <louis@jan.ai> * chore: refactor * fix: load models empty first time open * Add Docker compose * fix: assistants onUpdate --------- Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai> Co-authored-by: Hien To <tominhhien97@gmail.com> Co-authored-by: NamH <NamNh0122@gmail.com>
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import { useCallback } from 'react'
|
|
|
|
import {
|
|
InferenceEvent,
|
|
ExtensionTypeEnum,
|
|
Thread,
|
|
events,
|
|
ConversationalExtension,
|
|
} from '@janhq/core'
|
|
|
|
import { useSetAtom } from 'jotai'
|
|
|
|
import { extensionManager } from '@/extension'
|
|
import { setConvoMessagesAtom } from '@/helpers/atoms/ChatMessage.atom'
|
|
import {
|
|
ModelParams,
|
|
isGeneratingResponseAtom,
|
|
setActiveThreadIdAtom,
|
|
setThreadModelParamsAtom,
|
|
} from '@/helpers/atoms/Thread.atom'
|
|
|
|
export default function useSetActiveThread() {
|
|
const setActiveThreadId = useSetAtom(setActiveThreadIdAtom)
|
|
const setThreadMessage = useSetAtom(setConvoMessagesAtom)
|
|
const setThreadModelParams = useSetAtom(setThreadModelParamsAtom)
|
|
const setIsGeneratingResponse = useSetAtom(isGeneratingResponseAtom)
|
|
|
|
const setActiveThread = useCallback(
|
|
async (thread: Thread) => {
|
|
setIsGeneratingResponse(false)
|
|
events.emit(InferenceEvent.OnInferenceStopped, thread.id)
|
|
|
|
// load the corresponding messages
|
|
const messages = await getLocalThreadMessage(thread.id)
|
|
setThreadMessage(thread.id, messages)
|
|
|
|
setActiveThreadId(thread.id)
|
|
const modelParams: ModelParams = {
|
|
...thread.assistants[0]?.model?.parameters,
|
|
...thread.assistants[0]?.model?.settings,
|
|
}
|
|
setThreadModelParams(thread.id, modelParams)
|
|
},
|
|
[
|
|
setActiveThreadId,
|
|
setThreadMessage,
|
|
setThreadModelParams,
|
|
setIsGeneratingResponse,
|
|
]
|
|
)
|
|
|
|
return { setActiveThread }
|
|
}
|
|
|
|
const getLocalThreadMessage = async (threadId: string) =>
|
|
extensionManager
|
|
.get<ConversationalExtension>(ExtensionTypeEnum.Conversational)
|
|
?.getAllMessages(threadId) ?? []
|