From b4b8c862c030c99e6e49b6ef135ea72cafd5f2db Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 24 Apr 2024 21:17:19 +0700 Subject: [PATCH] fix: infinite talking in auto thread titles generators (#2810) --- web/containers/Providers/EventHandler.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/web/containers/Providers/EventHandler.tsx b/web/containers/Providers/EventHandler.tsx index f772dd6cb..e4c96aeb7 100644 --- a/web/containers/Providers/EventHandler.tsx +++ b/web/containers/Providers/EventHandler.tsx @@ -20,6 +20,8 @@ import { ulid } from 'ulidx' import { activeModelAtom, stateModelAtom } from '@/hooks/useActiveModel' +import { toRuntimeParams } from '@/utils/modelParam' + import { extensionManager } from '@/extension' import { getCurrentChatMessagesAtom, @@ -32,6 +34,7 @@ import { threadsAtom, isGeneratingResponseAtom, updateThreadAtom, + getActiveThreadModelParamsAtom, } from '@/helpers/atoms/Thread.atom' const maxWordForThreadTitle = 10 @@ -54,6 +57,8 @@ export default function EventHandler({ children }: { children: ReactNode }) { const updateThread = useSetAtom(updateThreadAtom) const messagesRef = useRef(messages) const activeModelRef = useRef(activeModel) + const activeModelParams = useAtomValue(getActiveThreadModelParamsAtom) + const activeModelParamsRef = useRef(activeModelParams) useEffect(() => { threadsRef.current = threads @@ -71,6 +76,10 @@ export default function EventHandler({ children }: { children: ReactNode }) { activeModelRef.current = activeModel }, [activeModel]) + useEffect(() => { + activeModelParamsRef.current = activeModelParams + }, [activeModelParams]) + const onNewMessageResponse = useCallback( (message: ThreadMessage) => { if (message.type === MessageRequestType.Thread) { @@ -247,6 +256,8 @@ export default function EventHandler({ children }: { children: ReactNode }) { }, ] + const runtimeParams = toRuntimeParams(activeModelParamsRef.current) + const messageRequest: MessageRequest = { id: msgId, threadId: message.thread_id, @@ -255,6 +266,7 @@ export default function EventHandler({ children }: { children: ReactNode }) { model: { ...activeModelRef.current, parameters: { + ...runtimeParams, stream: false, }, },