-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
【问题描述】:
部分场景下,大模型流式可能会同时返回 delta 和 message,这个时候需要兼容处理。
示例:魔搭 modelscope 会同时返回 deleta 和空 message。
{
"id": "chatcmpl-052745f8-e891-9566-bbf5-8b56dc1b8478",
"object": "chat.completion.chunk",
"created": 1769842040,
"model": "Qwen/Qwen3-VL-235B-A22B-Instruct",
"system_fingerprint": "",
"choices": [
{
"index": 0,
"delta": {
"role": null,
"content": "",
"tool_calls": null,
"function_calls": null,
"reasoning_content": ""
},
"finish_reason": "stop",
"message": {
"role": null,
"content": "",
"tool_calls": null,
"function_calls": null,
"reasoning_content": ""
}
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
}
}关联代码:
tiny-robot/packages/kit/src/vue/message/useMessage.ts
Lines 199 to 222 in b599aa5
| if (choice) { | |
| lastChoice = choice | |
| const runDefault = () => { | |
| // Ensure metadata exists | |
| if (!message.metadata) { | |
| message.metadata = {} | |
| } | |
| const { created, ...rest } = chunk | |
| message.metadata.createdAt = created | |
| message.metadata.updatedAt = Math.floor(Date.now() / 1000) | |
| Object.assign(message.metadata, rest) | |
| combileDeltaData(message, choice.message || choice.delta) | |
| } | |
| if (onCompletionChunk) { | |
| const baseContext = getBaseContext(abortSignal) | |
| onCompletionChunk({ ...baseContext, chunk, choice, currentMessage: message }, runDefault) | |
| } else { | |
| runDefault() | |
| } | |
| } |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels