抓包对比工具补一批一次性脚本:拆预设、对请求、跑 A/B 与拒答抽样。

这些脚本都是我对着酒馆真实请求手工核对用的,留在仓库里方便下次重跑;跑出来的本地数据目录含接口 key,已经写进忽略规则。
This commit is contained in:
2026-10-26 01:09:56 +08:00
parent e2413b0677
commit 1a5ef3b2bc
24 changed files with 1568 additions and 0 deletions
@@ -0,0 +1,40 @@
// 拆解抓包里的 tools[].function.description:它到底装了什么
// 用法: node analyze-tool-desc.mjs <capture.json> [preset.json]
import { readFileSync } from "node:fs";
const outer = JSON.parse(readFileSync(process.argv[2], "utf8"));
const body = JSON.parse(outer.body);
const tools = body.tools || [];
console.log("tools 数量: " + tools.length + ",tool_choice=" + JSON.stringify(body.tool_choice));
tools.forEach((t, i) => {
const fn = t.function || t;
const d = String(fn.description || "");
console.log("\n=== tools[" + i + "] name=" + fn.name + " description=" + d.length + " 字 ===");
console.log("parameters: " + JSON.stringify(fn.parameters || {}).slice(0, 400));
const heads = d.split("\n").filter((l) => /^(#{1,3}\s|===|---|\[[A-Za-z_]+|<[A-Za-z_]+>)/.test(l.trim())).slice(0, 60);
console.log("\n-- 段落标题/标记(前 60 行)--");
console.log(heads.join("\n"));
console.log("\n-- 开头 700 字 --");
console.log(d.slice(0, 700));
console.log("\n-- 中段 700 字(45% 处)--");
console.log(d.slice(Math.floor(d.length * 0.45), Math.floor(d.length * 0.45) + 700));
console.log("\n-- 结尾 500 字 --");
console.log(d.slice(-500));
});
// 如果给了预设,逐条看哪些 block 被塞进 description
if (process.argv[3]) {
const preset = JSON.parse(readFileSync(process.argv[3], "utf8"));
const d = tools.map((t) => String((t.function || t).description || "")).join("\n");
const norm = (s) => String(s || "").replace(/\s+/g, " ").trim();
const pool = norm(d);
console.log("\n=== 预设条目 → 是否进了 tool description ===");
let sum = 0;
for (const p of preset.prompts || []) {
const c = norm(p.content);
if (c.length < 60) continue;
const hit = pool.includes(c.slice(0, 120)) || pool.includes(c.slice(-120));
if (hit) sum += String(p.content).length;
console.log((hit ? "✅" : " ") + " " + String(p.name || p.identifier).slice(0, 34) + " (" + String(p.content).length + " 字)");
}
console.log("\n被吞进 description 的预设正文字数合计 ≈ " + sum);
}