返回首页

Claude 优化:短语 -9.5% tokens

分析显示,Claude Sonnet 在不必要短语上花费 11.3% tokens。将规则添加到 system prompt 可将消耗减少至 1.8%,每月节省数千卢布。适用于机器集成,聊天需注意。

Claude 在 "Of course!" 上花费 11%:如何节省 9.5% tokens
Advertisement 728x90

# Claude 提示词优化:砍掉填充短语节省 9.5% 令牌

像 Claude Sonnet 这样的模型在输出中会浪费高达 11% 的令牌于开场白、元评论和结束语。针对 500 个提示词测试显示,系统提示中添加三行指令就能大幅减少这种浪费,同时不损失任何响应价值。

分析显示响应中 11.3% 是“填充”内容:模型开头常说“当然!”或“好问题!”,中间插入边想边说的解释,结尾用“希望这有帮助”。对于后端 JSON 解析集成,这纯属多余开销。

测试方法

我们收集了 500 个典型任务:工单分类、文档字段提取、邮件摘要、基于策略的回复。设置:claude-sonnet-4-5temperature=0.2,标准系统提示。

Google AdInline article slot

用 Python 脚本和正则表达式解析输出:

FILLER_PATTERNS = [
    r"^(Sure|Absolutely|Of course|Okay)[,!.]",
    r"^(Great|Great question|Excellent)[!.]",
    r"^(Happy to|Glad to)",
    r"^(Let's|Allow me)",
    r"(Hope this (helps|will help))",
    r"(If you have (any )?(more )?questions)",
    r"(Let me know if)",
]

手动审核 50 个响应,准确率达 94%。其余为漏计。

填充内容分布:

Google AdInline article slot
  • 开场短语(“当然!”、“好问题!”) — 28%
  • 元评论(“让我想想……”) — 34%
  • 结束短语(“希望这有帮助”) — 22%
  • 问题改述 — 16%

手动清理 100 个响应,保留核心含义。

系统提示优化

原提示:

You are an assistant for processing [DOMAIN]. Respond precisely,
basing answers only on provided context. If no data — say so honestly.

新增:

Google AdInline article slot
Response format:
- No intros, question praise, or "here's what I'll do" explanations.
- No closers like "hope that helps."
- Straight to the point. Lists first if needed. Numbers first if needed.

重新运行 500 个提示:填充降至 1.8%。令牌节省:9.5%。

成本示例:

| 日查询量 | 平均响应(令牌) | 月节省(美元) |

|----------|------------------|----------------|

| 2000 | 400 | ~50 |

| 20000 | 400 | ~500 |

实际项目:每月节省 55 美元。后续对话上下文更短。

局限性与回滚

并非所有场景适用:

  • 客户聊天:去除礼貌语显得生硬。满意度下降 — 已回滚。
  • 工具链调用:无计划描述时模型工具混淆。为可靠性回滚。

提示:适用于机器面向任务(JSON、API)。用户聊天保留礼貌。

关键要点

  • 基准 Claude Sonnet 填充占 11.3% 令牌。
  • 三行提示节省 9.5%。
  • 正则捕获 94% 废话。
  • 响应本质安全,工具链和用户体验聊天有风险。
  • 下一步:清理用户前言输入令牌。

— Editorial Team

Advertisement 728x90

继续阅读