返回顶部
P

Prompt Token Analyzer 提示令牌分析器

A Node.js CLI tool that analyzes prompt token usage using a GPT-compatible tokenizer. Helps agents estimate prompt size, debug context overflow, and optimize token cost.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.1
安全检测
已通过
230
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

Prompt Token Analyzer

提示词令牌分析器

提示词令牌分析器是一款轻量级CLI工具,用于计算提示词包含的令牌数量。
它使用gpt-tokenizer包来近似模拟GPT风格的令牌化处理。

该工具可帮助AI智能体和开发者:

  • - 估算提示词大小
  • 减少不必要的令牌使用
  • 调试大型提示词
  • 优化RAG管道

安装

安装令牌化器:

bash
npm install -g gpt-tokenizer

创建CLI工具:

bash
cat < prompt-token
#!/usr/bin/env node

import { encode } from gpt-tokenizer
import fs from fs

const args = process.argv.slice(2)

if (args.length === 0) {
console.log(用法:)
console.log( prompt-token analyze <文件>)
console.log( prompt-token text \您的提示词\)
process.exit(1)
}

let text =

if (args[0] === analyze) {
const file = args[1]

if (!file) {
console.error(缺少文件路径)
process.exit(1)
}

text = fs.readFileSync(file, utf8)
}

else if (args[0] === text) {
text = args.slice(1).join( )
}

else {
console.error(未知命令)
process.exit(1)
}

const tokens = encode(text)

console.log(提示词令牌分析)
console.log(---------------------)
console.log(字符数:, text.length)
console.log(令牌数:, tokens.length)
console.log(平均字符/令牌:, (text.length / tokens.length).toFixed(2))

const estimatedCost = tokens.length / 1000000 * 5

console.log()
console.log(预估成本(示例 $5 / 100万令牌):)
console.log($ + estimatedCost.toFixed(6))

EOF

使工具可执行:

bash
chmod +x prompt-token

将其移动到PATH路径:

bash
sudo mv prompt-token /usr/local/bin/



快速开始

分析提示词文件:

bash
prompt-token analyze prompt.txt

示例输出:

提示词令牌分析



字符数:7341
令牌数:1832
平均字符/令牌:4.01

预估成本(示例 $5 / 100万令牌):
$0.009160



分析原始文本

bash
prompt-token text 用简单术语解释强化学习

示例输出:

提示词令牌分析



字符数:47
令牌数:9
平均字符/令牌:5.22


使用场景

提示词工程

衡量提示词变化如何影响令牌大小。

bash
prompt-token text 您是一个AI助手...



RAG上下文分析

在将检索到的文档发送给LLM之前,检查其大小。

bash
prompt-token analyze rag_context.txt



调试上下文溢出

大型提示词可能超出模型限制。

在发送给模型之前对其进行分析。



故障排除

如果令牌化器缺失:

bash
npm install -g gpt-tokenizer

检查Node安装:

bash
node --version



注意事项

  • - 令牌计数为近似值,但接近OpenAI风格的令牌化处理。
  • 实际API使用可能包含额外的系统令牌。
  • 长RAG上下文是令牌浪费的最常见原因。

报告问题

如有需要,重新安装令牌化器:

bash
npm install -g gpt-tokenizer

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 prompt-token-analyzer-1776110063 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 prompt-token-analyzer-1776110063 技能

通过命令行安装

skillhub install prompt-token-analyzer-1776110063

下载

⬇ 下载 Prompt Token Analyzer v1.0.1(免费)

文件大小: 2.15 KB | 发布时间: 2026-4-15 14:01

v1.0.1 最新 2026-4-15 14:01
- Revised and clarified documentation for better readability and structure.
- Improved sections for installation, quick start, and troubleshooting.
- Simplified explanations of use cases and benefits.
- Removed redundant instructions and streamlined CLI setup steps.
- Added guidance for reporting and resolving issues.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部