抓包对比工具补一批一次性脚本:拆预设、对请求、跑 A/B 与拒答抽样。
这些脚本都是我对着酒馆真实请求手工核对用的,留在仓库里方便下次重跑;跑出来的本地数据目录含接口 key,已经写进忽略规则。
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// 把一侧请求里的每条消息,回溯到预设的哪个条目,并判断是「原样 / 前缀截断 / 改写」
|
||||
// 用法: node match-msg.mjs <preset.json> <capture.json>
|
||||
import { readFileSync } from "node:fs";
|
||||
const preset = JSON.parse(readFileSync(process.argv[2], "utf8"));
|
||||
const outer = JSON.parse(readFileSync(process.argv[3], "utf8"));
|
||||
const body = JSON.parse(outer.body);
|
||||
const prompts = (preset.prompts || []).filter((p) => String(p.content ?? "").trim());
|
||||
const norm = (s) => String(s ?? "").replace(/\s+/g, " ").trim();
|
||||
|
||||
body.messages.forEach((m, i) => {
|
||||
const text = norm(m.content);
|
||||
const head = text.slice(0, 80);
|
||||
let best = null;
|
||||
for (const p of prompts) {
|
||||
const c = norm(p.content);
|
||||
const p80 = c.slice(0, 80);
|
||||
let score = 0;
|
||||
for (let k = 0; k < Math.min(p80.length, head.length); k++) {
|
||||
if (p80[k] === head[k]) score++;
|
||||
else break;
|
||||
}
|
||||
if (!best || score > best.score) best = { name: p.name || p.identifier, len: c.length, score };
|
||||
}
|
||||
const ratio = best && best.len ? (text.length / best.len).toFixed(2) : "-";
|
||||
console.log(
|
||||
"#" + i + " [" + m.role + "] " + text.length + " 字 ← " + (best ? best.name : "?") + " (预设 " + (best ? best.len : 0) + " 字, 前80字重合 " + (best ? best.score : 0) + ", 长度比 " + ratio + ")",
|
||||
);
|
||||
console.log(" 头: " + head.slice(0, 70));
|
||||
console.log(" 尾: " + text.slice(-70));
|
||||
});
|
||||
Reference in New Issue
Block a user