自动化对比测试多个 LLM 模型在相同任务上的表现,记录速度、Token 消耗、成功率等指标,生成标准化 JSON 报告。适用于模型选型、Prompt 优化、成本评估等场景。
使用场景:
功能说明多模型对比同时测试多个模型,自动对比结果批量测试支持多个样本文件和 Prompt 模板性能记录自动记录耗时、Token 消耗、成功率超时控制单个模型超时自动跳过,不阻塞其他模型JSON 报告标准化输出,易于集成 CI/CD
bash
# 基本用法
python3 scripts/llm_benchmark.py --samples samples/ --prompts prompts/ --models qwen3.6-plus qwen3-max
# 指定超时和输出路径
python3 scripts/llm_benchmark.py \
--samples samples/ \
--prompts prompts/ \
--models qwen3.6-plus qwen3-max-2026-01-23 \
--timeout 90 \
--output reports/report.json
# 简写
python3 scripts/llm_benchmark.py -s samples/ -p prompts/ -m qwen3.6-plus qwen3-max -t 90 -o report.json
参数必填说明--samples / -s✅测试样本目录(包含 .txt 文件)--prompts / -p✅Prompt 模板目录(包含 .txt 文件)--models / -m❌要测试的模型列表(默认:qwen3.6-plus qwen3-max)--timeout / -t❌单个模型超时时间(秒,默认 60)--output / -o❌报告输出路径(默认:reports/benchmark-report.json)
变量说明默认值DASHSCOPE_API_KEYAPI Key无(必须设置)LLM_API_BASEAPI 地址https://coding.dashscope.aliyuncs.com/v1/chat/completions
纯文本文件,每个文件一个测试样本。
使用 {text} 占位符,运行时替换为样本内容。
txt
分析以下文本的写作风格,输出 JSON:
{"complexity": "简洁或复杂", "pace": "快速/舒缓/紧凑", "labels": ["标签1", "标签2", "标签3"]}
文本:
{text}
json
{
"timestamp": "2026-04-14 13:30:00",
"config": {
"samples_dir": "samples/",
"prompts_dir": "prompts/",
"models": ["qwen3.6-plus", "qwen3-max-2026-01-23"],
"timeout": 60
},
"summary": {
"qwen3.6-plus": {
"success_rate": "16/16 (100%)",
"avg_time": "43.8s",
"avg_tokens": "2952",
"total_time": "701.4s",
"total_tokens": 47230
},
"qwen3-max-2026-01-23": {
"success_rate": "16/16 (100%)",
"avg_time": "6.1s",
"avg_tokens": "735",
"total_time": "97.7s",
"total_tokens": 11762
}
},
"results": {
"chapter_1_style-analysis": {
"qwen3.6-plus": {"status": "success", "time": 36.13, "tokens": 2496, "result": {...}},
"qwen3-max-2026-01-23": {"status": "success", "time": 13.12, "tokens": 707, "result": {...}}
}
}
}
安装依赖:
bash
pip install -r scripts/requirements.txt
bash
# 测试风格分析能力
python3 scripts/llm_benchmark.py \
--samples samples/novel-chapters/ \
--prompts prompts/style-analysis.txt \
--models qwen3.6-plus qwen3-max \
--output reports/style-benchmark.json
bash
# 测试伏笔识别能力
python3 scripts/llm_benchmark.py \
--samples samples/novel-chapters/ \
--prompts prompts/foreshadowing.txt \
--models qwen3.6-plus qwen3-max \
--output reports/foreshadowing-benchmark.json
DASHSCOPE_API_KEY 环境变量{text} 占位符.txt 格式