fix: refresh thinking state on streaming (#5557)

This commit is contained in:
one 2025-05-01 01:08:22 +08:00 committed by GitHub
parent d571c46aad
commit f9690d52ee
3 changed files with 20 additions and 1 deletions

View File

@ -259,7 +259,17 @@ export default class AnthropicProvider extends BaseProvider {
.on('text', (text) => { .on('text', (text) => {
if (hasThinkingContent && !checkThinkingContent) { if (hasThinkingContent && !checkThinkingContent) {
checkThinkingContent = true checkThinkingContent = true
onChunk({ type: ChunkType.THINKING_COMPLETE, text: thinking_content, thinking_millsec: 0 }) onChunk({
type: ChunkType.THINKING_COMPLETE,
text: thinking_content,
thinking_millsec: time_first_content_millsec - time_first_token_millsec
})
// FIXME: 临时方案,重置时间戳和思考内容
time_first_token_millsec = 0
time_first_content_millsec = 0
thinking_content = ''
checkThinkingContent = false
hasThinkingContent = false
} }
if (time_first_token_millsec == 0) { if (time_first_token_millsec == 0) {
time_first_token_millsec = new Date().getTime() - start_time_millsec time_first_token_millsec = new Date().getTime() - start_time_millsec

View File

@ -559,6 +559,12 @@ export default class OpenAIProvider extends BaseProvider {
text: thinkingContent, text: thinkingContent,
thinking_millsec: final_time_thinking_millsec_delta thinking_millsec: final_time_thinking_millsec_delta
}) })
// FIXME: 临时方案,重置时间戳和思考内容
time_first_token_millsec = 0
time_first_content_millsec = 0
thinkingContent = ''
isFirstThinkingChunk = true
} }
} }

View File

@ -280,6 +280,9 @@ const fetchAndProcessAssistantResponseImpl = async (
if (newBlockType !== MessageBlockType.MAIN_TEXT) { if (newBlockType !== MessageBlockType.MAIN_TEXT) {
accumulatedContent = '' accumulatedContent = ''
} }
if (newBlockType !== MessageBlockType.THINKING) {
accumulatedThinking = ''
}
console.log(`[Transition] Adding/Updating new ${newBlockType} block ${newBlock.id}.`) console.log(`[Transition] Adding/Updating new ${newBlockType} block ${newBlock.id}.`)
dispatch( dispatch(
newMessagesActions.updateMessage({ newMessagesActions.updateMessage({