Repository navigation
[Feature] token圆环显示生成预留空间 #9251
Copy link
Copy link
Open
Labels
area:webuiThe bug / feature is about webui(dashboard) of astrbot.The bug / feature is about webui(dashboard) of astrbot.enhancementNew feature or requestNew feature or requestfeature:chatuiThe bug / feature is about astrbot's chatui, webchatThe bug / feature is about astrbot's chatui, webchat
Description
Description / 描述
描述
token 用量圆环当前只显示 used / limit,其中 limit = 模型的完整上下文窗口。以 deepseek-v4-pro 为例,limit = 1M tokens。
但上下文窗口并不等于是输入空间——LLM 需要预留一部分用于生成输出。deepseek-v4-pro 单次最大输出 384K tokens(来自 LLMMetadata.limit.output),圆环显示 80% 时用户觉得「还有 200K 挺安全」,实际上下次 LLM 调用如果模型想完整输出 384K,上下文直接溢出。
后端真实的压缩逻辑
后端在 82% 处触发上下文压缩(compression_threshold = 0.82),预留 18%。但对 deepseek-v4-pro:
| 指标 | 值 |
|---|---|
| 上下文窗口 | 1,048,576 (= 1M) |
| 后端压缩触发 | 860K(82%) |
| 后端预留 | ~180K |
| 模型最大输出 | 384K |
180K < 384K。后端压缩预留的空间,装不下单次最大输出。
数据已有
astrbot/core/utils/llm_metadata.py 的 LLMLimit 已经定义了 output 字段:
class LLMLimit(TypedDict):
context: int # 最大上下文窗口
output: int # 最大输出 tokens来自 models.dev API 动态拉取,无需新增数据源。
当前前端计算
dashboard/src/components/chat/Chat.vue 第 884 行:
const tokenUsageIndicator = computed(() => {
const used = latestTokenUsageTotal.value;
const limit = contextLimit(...); // 只用 limit.context
const percent = (used / limit) * 100;
});limit.output 完全没用上。
期望行为
采用单环三段式设计,与主流设计实践一致:
┌──────────────────────────────┐
│ ████████░░░░░░░░░░ │
│ █ used ░reserve ░free │
│ ████████░░░░░░░░░░ │
└──────────────────────────────┘
- 实色段:
used / limit— 已占用上下文 - 阴影/纹理段:
reserve / limit— 生成预留(min(max_output, limit - used)) - 空白段:剩余的真正可用空间
视觉效果(deepseek-v4-pro,1M/384K)
🟢 安全:
[████████░░░░░░░░░░░░░░░░░░░░ ]
used=200K reserve=384K free=416K
外环 20% 纹理 57% 剩余 43%
🟡 注意:
[████████████████████░░░░░░░░░░░░ ]
used=640K reserve=384K
实色 61% 纹理 98%(接近极限)
🔴 压缩:
[█████████████████████████░░░░░░░░░░░░]
used=860K (后端压缩触发!)
实色 82% / 纹理 119%(溢出!)
此时即使后端执行压缩,模型想完整输出 384K 仍会溢出。
核心价值:外环 61% 用户觉得「还挺空」,但加上阴影预留段后 98%,一目了然。
依赖
依赖 #9248(累加导致百分比虚高)先修——used 是累加值则内外圈全错。
需要等到 #9255 合并才能工作
Use Case / 使用场景
- 长对话末尾:外环 75% 时,阴影段直接从 75% 拉伸到 ~110%,用户立刻知道「不能再要大段回复了」
- 代码生成:预期输出 50K+,内环纹理让用户提前判断有无足够生成空间
- 成本感知:阴影段让用户直观理解「上下文窗口 = 输入 + 输出,不是全给输入用的」
Willing to Submit PR? / 是否愿意提交PR?
- Yes, I am willing to submit a PR. / 是的,我愿意提交 PR。
Code of Conduct
- I have read and agree to abide by the project's Code of Conduct. /
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area:webuiThe bug / feature is about webui(dashboard) of astrbot.The bug / feature is about webui(dashboard) of astrbot.enhancementNew feature or requestNew feature or requestfeature:chatuiThe bug / feature is about astrbot's chatui, webchatThe bug / feature is about astrbot's chatui, webchat
Activity