Repository navigation
修复:Qoder 模型归属回落 Auto + Anthropic 流式上下文用量恒 0 - #336
Open
tomliangzi wants to merge 2 commits into
Open
tomliangzi wants to merge 2 commits into
tomliangzi wants to merge 2 commits into
Conversation
官方 Qoder 客户端的 agent 循环在 business 块里固定携带当前模型键 (运行时 d8() 的第 5 个参数)。上游后台的模型归属/计费优先读它; Agent2API 之前只带 model_config.key 与 X-Model-Key,选择 Kimi-K3.1-Pro 等模型时后台一律记成账号默认档 Auto。 补上 business.model_key 后,同一请求在 Qoder 后台由 Auto 变为 Kimi-K3.1-Pro;新增单测锁住该字段。 Co-Authored-By: Claude Code <noreply@anthropic.com>
/v1/messages 流式响应收尾的 message_delta 原来只回传 output_tokens, 上游已拿到的 input_tokens / cache_read_input_tokens 被丢弃,客户端 (Claude Code context-hud)因此始终认为本次请求没有输入,上下文用量 恒为 0。 - message_delta 改用 usage_to_anthropic(self.usage),回传完整用量; - message_start 用请求体粗估的输入 token 数占位(真实值随后覆盖), 保证首帧也不是 0; - 估算为纯内存字符扫描,不增加网络等待。 Co-Authored-By: Claude Code <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
/v1/messages(Claude Code)时,context-hud 的上下文用量始终为 0。原因
business块里固定携带当前模型键(官方运行时d8()的第 5 个参数即model_key)。上游后台的模型归属优先读它;此前只发送model_config.key与X-Model-Key,缺少business.model_key时会回落到账号默认档 Auto。message_delta只回传output_tokens,上游已拿到的input_tokens/cache_read_input_tokens被丢弃;message_start又只能在首帧发 0 占位,客户端因此无法感知上下文用量。改动
qoder/protocol.rs:business增加model_key,并新增单测锁住该字段。anthropic.rs:message_delta改用usage_to_anthropic回传完整 usage;新增estimate_chat_tokens,message_start用请求体估算值占位(真实值随后覆盖)。api/protocol.rs:把估算值接入AnthropicStream::with_input_tokens。验证
cargo test:586 passed,0 failed(新增 1 条回归测试)。/v1/messages流式message_start返回估算 input,message_delta返回真实input_tokens=90 / output_tokens=32 / cache_read_input_tokens=0。🤖 Generated with Claude Code