fix: imporve the condition for stopping the think timer. (#25365)
This commit is contained in:
parent
08dd3f7b50
commit
928bef9d82
1 changed files with 4 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
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')
|
||||||
|
|
@ -35,6 +36,7 @@ const removeEndThink = (children: any): any => {
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|
@ -54,9 +56,9 @@ const useThinkTimer = (children: any) => {
|
||||||
}, [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…
Add table
Add a link
Reference in a new issue