mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
feat(agent): 增加最终模型请求预算观测 (#6290)
This commit is contained in:
+53
-12
@@ -1386,7 +1386,11 @@ class MessageChain(ChainBase):
|
||||
last_input_tokens = status.get("last_input_tokens")
|
||||
if context_window_tokens and status.get("model_call_count"):
|
||||
context_ratio = status.get("last_context_usage_ratio")
|
||||
if context_ratio is None and last_input_tokens is not None:
|
||||
if (
|
||||
context_ratio is None
|
||||
and status.get("last_input_usage_available") is True
|
||||
and last_input_tokens is not None
|
||||
):
|
||||
context_ratio = last_input_tokens / context_window_tokens
|
||||
context_usage_text = (
|
||||
f"{cls._format_token_count(last_input_tokens)} / "
|
||||
@@ -1405,17 +1409,45 @@ class MessageChain(ChainBase):
|
||||
f"当前模型: {status.get('model') or '未知'}",
|
||||
f"上下文窗口: {cls._format_token_count(context_window_tokens)} tokens",
|
||||
f"最近一次上下文占用: {context_usage_text}",
|
||||
f"最近一次 tokens: 输入 {cls._format_token_count(status.get('last_input_tokens'))} / 输出 {cls._format_token_count(status.get('last_output_tokens'))} / 总计 {cls._format_token_count(status.get('last_total_tokens'))}",
|
||||
f"当前会话累计 tokens: 输入 {cls._format_token_count(status.get('total_input_tokens'))} / 输出 {cls._format_token_count(status.get('total_output_tokens'))} / 总计 {cls._format_token_count(status.get('total_tokens'))}",
|
||||
f"模型调用次数: {status.get('model_call_count', 0)}",
|
||||
f"排队消息数: {status.get('pending_messages', 0)}",
|
||||
f"最后更新: {status.get('last_updated_at') or '暂无'}",
|
||||
]
|
||||
if status.get("cache_usage_available"):
|
||||
if status.get("last_request_estimate_available"):
|
||||
estimated_tokens = status.get("last_estimated_input_tokens")
|
||||
estimated_ratio = status.get("last_estimated_input_ratio")
|
||||
estimate_text = (
|
||||
f"{cls._format_token_count(estimated_tokens)} / "
|
||||
f"{cls._format_token_count(context_window_tokens)}"
|
||||
)
|
||||
if estimated_ratio is not None:
|
||||
estimate_text += f" ({estimated_ratio * 100:.2f}%)"
|
||||
if status.get("last_estimated_over_input_limit"):
|
||||
estimate_text += ",估算已超输入上限"
|
||||
lines.extend(
|
||||
[
|
||||
f"最终请求估算: {estimate_text}",
|
||||
"估算组成: "
|
||||
f"消息 {cls._format_token_count(status.get('last_estimated_message_tokens'))} / "
|
||||
f"系统 {cls._format_token_count(status.get('last_estimated_system_tokens'))} / "
|
||||
f"工具 {cls._format_token_count(status.get('last_estimated_tool_tokens'))} / "
|
||||
f"其中图片固定成本 {cls._format_token_count(status.get('last_estimated_multimodal_tokens'))}",
|
||||
]
|
||||
)
|
||||
actual_input_tokens = status.get("last_actual_input_tokens")
|
||||
estimate_error_tokens = status.get("last_estimate_error_tokens")
|
||||
if actual_input_tokens is not None and estimate_error_tokens is not None:
|
||||
estimate_error_ratio = status.get("last_estimate_error_ratio")
|
||||
error_text = (
|
||||
f"实际 {cls._format_token_count(actual_input_tokens)} / "
|
||||
f"误差 {estimate_error_tokens:+,}"
|
||||
)
|
||||
if estimate_error_ratio is not None:
|
||||
error_text += f" ({estimate_error_ratio:+.2%})"
|
||||
lines.append(f"估算校准: {error_text}")
|
||||
lines.append(
|
||||
f"最近一次 tokens: 输入 {cls._format_token_count(status.get('last_input_tokens'))} / 输出 {cls._format_token_count(status.get('last_output_tokens'))} / 总计 {cls._format_token_count(status.get('last_total_tokens'))}"
|
||||
)
|
||||
if status.get("last_cache_usage_available"):
|
||||
last_cache_ratio = status.get("last_cache_hit_ratio")
|
||||
total_cache_ratio = status.get("total_cache_hit_ratio")
|
||||
lines.insert(
|
||||
6,
|
||||
lines.append(
|
||||
"最近一次缓存: "
|
||||
f"命中 {cls._format_token_count(status.get('last_cache_read_input_tokens'))} / "
|
||||
f"写入 {cls._format_token_count(status.get('last_cache_write_input_tokens'))} / "
|
||||
@@ -1426,8 +1458,9 @@ class MessageChain(ChainBase):
|
||||
else ""
|
||||
),
|
||||
)
|
||||
lines.insert(
|
||||
8,
|
||||
if status.get("cache_usage_available"):
|
||||
total_cache_ratio = status.get("total_cache_hit_ratio")
|
||||
lines.append(
|
||||
"当前会话累计缓存: "
|
||||
f"命中 {cls._format_token_count(status.get('total_cache_read_input_tokens'))} / "
|
||||
f"写入 {cls._format_token_count(status.get('total_cache_write_input_tokens'))} / "
|
||||
@@ -1438,6 +1471,14 @@ class MessageChain(ChainBase):
|
||||
else ""
|
||||
),
|
||||
)
|
||||
lines.extend(
|
||||
[
|
||||
f"当前会话累计 tokens: 输入 {cls._format_token_count(status.get('total_input_tokens'))} / 输出 {cls._format_token_count(status.get('total_output_tokens'))} / 总计 {cls._format_token_count(status.get('total_tokens'))}",
|
||||
f"模型调用次数: {status.get('model_call_count', 0)}",
|
||||
f"排队消息数: {status.get('pending_messages', 0)}",
|
||||
f"最后更新: {status.get('last_updated_at') or '暂无'}",
|
||||
]
|
||||
)
|
||||
return "\n".join(lines)
|
||||
|
||||
def remote_session_status(
|
||||
|
||||
Reference in New Issue
Block a user