Browse Source

fix: imporve the condition for stopping the think timer. (#25365)

tags/1.9.0
17hz 1 month ago
parent
commit
928bef9d82
No account linked to committer's email address
1 changed files with 4 additions and 2 deletions
  1. 4
    2
      web/app/components/base/markdown-blocks/think-block.tsx

+ 4
- 2
web/app/components/base/markdown-blocks/think-block.tsx View File

import React, { useEffect, useRef, useState } from 'react' import React, { useEffect, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { useChatContext } from '../chat/chat/context'


const hasEndThink = (children: any): boolean => { const hasEndThink = (children: any): boolean => {
if (typeof children === 'string') if (typeof children === 'string')
} }


const useThinkTimer = (children: any) => { const useThinkTimer = (children: any) => {
const { isResponding } = useChatContext()
const [startTime] = useState(Date.now()) const [startTime] = useState(Date.now())
const [elapsedTime, setElapsedTime] = useState(0) const [elapsedTime, setElapsedTime] = useState(0)
const [isComplete, setIsComplete] = useState(false) const [isComplete, setIsComplete] = useState(false)
}, [startTime, isComplete]) }, [startTime, isComplete])


useEffect(() => { useEffect(() => {
if (hasEndThink(children))
if (hasEndThink(children) || !isResponding)
setIsComplete(true) setIsComplete(true)
}, [children])
}, [children, isResponding])


return { elapsedTime, isComplete } return { elapsedTime, isComplete }
} }

Loading…
Cancel
Save