mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-27 21:01:32 +08:00
fix: adjust thinking millisecond handling in message thunk
This commit is contained in:
parent
c565d91591
commit
c2f23d6916
@ -189,7 +189,7 @@ export const TEXT_TO_IMAGE_REGEX = /flux|diffusion|stabilityai|sd-|dall|cogview|
|
||||
|
||||
// Reasoning models
|
||||
export const REASONING_REGEX =
|
||||
/^(o\d+(?:-[\w-]+)?|.*\b(?:reasoner|thinking)\b.*|.*-[rR]\d+.*|.*\bqwq(?:-[\w-]+)?\b.*|.*\bhunyuan-t1(?:-[\w-]+)?\b.*|.*\bglm-zero-preview\b.*|.*\bgrok-3-mini(?:-[\w-]+)?\b.*)$/i
|
||||
/^(o\d+(?:-[\w-]+)?|.*\b(?:reasoning|reasoner|thinking)\b.*|.*-[rR]\d+.*|.*\bqwq(?:-[\w-]+)?\b.*|.*\bhunyuan-t1(?:-[\w-]+)?\b.*|.*\bglm-zero-preview\b.*|.*\bgrok-3-mini(?:-[\w-]+)?\b.*)$/i
|
||||
|
||||
// Embedding models
|
||||
export const EMBEDDING_REGEX =
|
||||
|
||||
@ -2,7 +2,7 @@ import { CheckOutlined } from '@ant-design/icons'
|
||||
import { useSettings } from '@renderer/hooks/useSettings'
|
||||
import { MessageBlockStatus, type ThinkingMessageBlock } from '@renderer/types/newMessage'
|
||||
import { Collapse, message as antdMessage, Tooltip } from 'antd'
|
||||
import { memo, useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import BarLoader from 'react-spinners/BarLoader'
|
||||
import styled from 'styled-components'
|
||||
@ -17,6 +17,8 @@ const ThinkingBlock: React.FC<Props> = ({ block }) => {
|
||||
const { t } = useTranslation()
|
||||
const { messageFont, fontSize, thoughtAutoCollapse } = useSettings()
|
||||
const [activeKey, setActiveKey] = useState<'thought' | ''>(thoughtAutoCollapse ? '' : 'thought')
|
||||
const [thinkingTime, setThinkingTime] = useState(block.thinking_millsec || 0)
|
||||
const intervalId = useRef<NodeJS.Timeout>(null)
|
||||
|
||||
const isThinking = useMemo(() => block.status === MessageBlockStatus.STREAMING, [block.status])
|
||||
|
||||
@ -50,13 +52,28 @@ const ThinkingBlock: React.FC<Props> = ({ block }) => {
|
||||
}
|
||||
}, [block.content, t])
|
||||
|
||||
useEffect(() => {
|
||||
if (isThinking) {
|
||||
intervalId.current = setInterval(() => {
|
||||
setThinkingTime((prev) => prev + 200)
|
||||
}, 200)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (intervalId.current) {
|
||||
window.clearInterval(intervalId.current)
|
||||
}
|
||||
}
|
||||
}, [isThinking])
|
||||
|
||||
const thinkingTimeSeconds = useMemo(() => (thinkingTime / 1000).toFixed(1), [thinkingTime])
|
||||
|
||||
if (!block.content) {
|
||||
return null
|
||||
}
|
||||
|
||||
const thinkingTime = block.thinking_millsec || 0
|
||||
const thinkingTimeSeconds = (thinkingTime / 1000).toFixed(1)
|
||||
|
||||
return (
|
||||
<CollapseContainer
|
||||
activeKey={activeKey}
|
||||
|
||||
@ -59,7 +59,7 @@ export function createStreamProcessor(callbacks: StreamProcessorCallbacks = {})
|
||||
callbacks.onTextComplete(data.text)
|
||||
}
|
||||
if (data.type === ChunkType.THINKING_DELTA && callbacks.onThinkingChunk) {
|
||||
callbacks.onThinkingChunk(data.text, data.thinking_millsec)
|
||||
callbacks.onThinkingChunk(data.text)
|
||||
}
|
||||
if (data.type === ChunkType.THINKING_COMPLETE && callbacks.onThinkingComplete) {
|
||||
callbacks.onThinkingComplete(data.text, data.thinking_millsec)
|
||||
|
||||
@ -398,7 +398,7 @@ const fetchAndProcessAssistantResponseImpl = async (
|
||||
} else {
|
||||
const newBlock = createThinkingBlock(assistantMsgId, accumulatedThinking, {
|
||||
status: MessageBlockStatus.STREAMING,
|
||||
thinking_millsec: thinking_millsec
|
||||
thinking_millsec: 0
|
||||
})
|
||||
handleBlockTransition(newBlock, MessageBlockType.THINKING)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user