支持流式 Chat Completions 输出 usage chunk#20
Conversation
AI PR Review RefusedThis PR targets |
There was a problem hiding this comment.
AI PR Review
Decision: comment
Confidence: 0.91
Summary
整体实现方向正确:已在三条流式路径中按 stream_options.include_usage=true 增加 usage: null 和末尾 choices: [] + usage chunk,并补充了对应回归测试。未发现会直接破坏主流程的明显问题,但有一处 usage 统计边界条件建议修正。
Findings
- [minor] services/protocol/openai_v1_chat_complete.py:79 -
completion_usage()中completion_tokens/reasoning_tokens的计算被if messages else 0保护,导致当messages为空但仍有输出内容时会错误返回 0。是否统计 completion token 不应依赖messages是否为空,建议改为基于content/reasoning_content本身判断。
Recent Comment Summary
功能与测试覆盖基本到位;建议修正 completion_usage() 中 completion/reasoning token 统计对 messages 的不必要依赖,以避免空消息场景下 usage 统计失真。
1506abc to
36313c2
Compare
There was a problem hiding this comment.
AI PR Review
Decision: comment
Confidence: 0.88
Summary
整体改动方向正确,已在三条流式路径(普通文本、Grok Console、Grok app-chat)统一实现 stream_options.include_usage=true 时的 usage 追加 chunk,并补充了对应回归测试。未发现明确阻塞性问题。
Findings
No specific findings were returned.
Recent Comment Summary
实现与测试覆盖基本完整,行为与预期一致;建议后续可再补充一个 messages=[] 场景下 usage 统计的边界测试以确认 token 计数策略。
|
这个 PR 初次提交时误选了 main,触发了上游的 wrong-target-branch 标签;当前账号无法移除该标签。后续改用新的 dev 目标 PR。 |
改动
stream_options.include_usage=true的 Chat Completions 流式 usage 输出。choices: []且包含usage的 chunk。usage: null。prompt_tokens、completion_tokens和total_tokens。验证
python -m py_compile services/protocol/openai_v1_chat_complete.py test/test_grok_provider.pypython -m unittest test.test_grok_provider.GrokProviderTests.test_streaming_grok_chat_completion_returns_openai_chunks test.test_grok_provider.GrokProviderTests.test_streaming_grok_console_completion_emits_reasoning_content test.test_grok_provider.GrokProviderTests.test_streaming_grok_console_completion_includes_usage_when_requested test.test_grok_provider.GrokProviderTests.test_streaming_grok_app_chat_completion_emits_reasoning_content test.test_grok_provider.GrokProviderTests.test_streaming_grok_app_chat_completion_includes_usage_when_requested test.test_grok_provider.GrokProviderTests.test_streaming_text_completion_includes_usage_when_requested关联 #19