fix: infinite talking in auto thread titles generators (#2810)

This commit is contained in:
Louis 2024-04-24 21:17:19 +07:00 committed by GitHub
parent 7d4cc67aa1
commit b4b8c862c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,
},
},