Skip to content

Commit

Permalink
fix: infinite talking in auto thread titles generators (janhq#2810)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan authored Apr 24, 2024
1 parent 7d4cc67 commit b4b8c86
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions web/containers/Providers/EventHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -32,6 +34,7 @@ import {
threadsAtom,
isGeneratingResponseAtom,
updateThreadAtom,
getActiveThreadModelParamsAtom,
} from '@/helpers/atoms/Thread.atom'

const maxWordForThreadTitle = 10
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -255,6 +266,7 @@ export default function EventHandler({ children }: { children: ReactNode }) {
model: {
...activeModelRef.current,
parameters: {
...runtimeParams,
stream: false,
},
},
Expand Down

0 comments on commit b4b8c86

Please sign in to comment.