清理: 撤销 namespace 引用体量入账估算

方案重审: ref 尾段携带长度牵动协议格式/解析/测试多处,
收益与复杂度不成比例; 退回估算器原口径, 另寻不改协议的入账路径
This commit is contained in:
lxy
2026-10-11 10:52:27 +08:00
parent 10cd9d2465
commit 3a1b8ccda9
3 changed files with 3 additions and 43 deletions
-9
View File
@@ -61,15 +61,6 @@ impl TokenEstimator {
/// 这里把 parts 的文本/base64 按同一 chars_ratio 粗估累加(base64 视为密集字符,0.35 偏保守)。
pub fn estimate_message(&self, msg: &ChatMessage) -> u32 {
let mut char_count = msg.content.chars().count();
// 939① 估算入账修正:Tool 消息 content 为 namespace 引用时,按 ref 尾段携带的
// 原文字节数入账(字节保守视作字符,中文会 3x 高估——方向安全:宁可高估触发
// 裁剪/压缩,不可漏估致预算门失效,后者曾致 provider 超限 400)。旧格式/已淘汰
// 内容(无 ?len= 尾段)按字面字符保守计,行为同前。
if matches!(msg.role, crate::provider::MessageRole::Tool) {
if let Some(n) = crate::namespace_store::parse_ref_content_len(&msg.content) {
char_count = n;
}
}
// url 图地板单独按 token 累加:地板语义是"每图至少 ~1600 token",必须生效于
// ×chars_ratio 折扣之后——若折进 char_count 会被 0.35 稀释成 560,1600 保底失效,
// 含 url 图消息的 history_tokens 低估 → 预算裁剪漏触发 → provider 超限 400。