fix: Update the state of the last message block as a fallback (#6076)

This commit is contained in:
SuYao 2025-05-16 22:21:05 +08:00 committed by GitHub
parent 35e27944f7
commit 04cbeab1d9
2 changed files with 18 additions and 3 deletions

View File

@ -718,9 +718,17 @@ export default class OpenAIProvider extends BaseOpenAIProvider {
const usage = chunk.usage
const originalFinishDelta = chunk.delta
const originalFinishRawChunk = chunk.chunk
if (!isEmpty(finishReason)) {
onChunk({ type: ChunkType.TEXT_COMPLETE, text: content })
if (content) {
onChunk({ type: ChunkType.TEXT_COMPLETE, text: content })
}
if (thinkingContent) {
onChunk({
type: ChunkType.THINKING_COMPLETE,
text: thinkingContent,
thinking_millsec: new Date().getTime() - time_first_token_millsec
})
}
if (usage) {
finalUsage.completion_tokens += usage.completion_tokens || 0
finalUsage.prompt_tokens += usage.prompt_tokens || 0
@ -812,7 +820,6 @@ export default class OpenAIProvider extends BaseOpenAIProvider {
if (toolResults.length) {
await processToolResults(toolResults, idx)
}
onChunk({
type: ChunkType.BLOCK_COMPLETE,
response: {

View File

@ -622,6 +622,14 @@ const fetchAndProcessAssistantResponseImpl = async (
const contextForUsage = userMsgIndex !== -1 ? orderedMsgs.slice(0, userMsgIndex + 1) : []
const finalContextWithAssistant = [...contextForUsage, finalAssistantMsg]
if (lastBlockId) {
const changes: Partial<MessageBlock> = {
status: MessageBlockStatus.SUCCESS
}
dispatch(updateOneBlock({ id: lastBlockId, changes }))
saveUpdatedBlockToDB(lastBlockId, assistantMsgId, topicId, getState)
}
// 更新topic的name
autoRenameTopic(assistant, topicId)