抓包对比工具补一批一次性脚本:拆预设、对请求、跑 A/B 与拒答抽样。
这些脚本都是我对着酒馆真实请求手工核对用的,留在仓库里方便下次重跑;跑出来的本地数据目录含接口 key,已经写进忽略规则。
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// 把预设文件导入正在运行的应用(默认 127.0.0.1:23337),导入后不切换当前预设。
|
||||
// 用法: node import-to-app.mjs <preset.json> [--port 23337]
|
||||
import { readFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
const file = process.argv[2];
|
||||
const portIndex = process.argv.indexOf("--port");
|
||||
const port = portIndex > 0 ? Number(process.argv[portIndex + 1]) : 23337;
|
||||
const raw = JSON.parse(readFileSync(file, "utf8"));
|
||||
const name = path.basename(file, ".json");
|
||||
|
||||
const res = await fetch("http://127.0.0.1:" + port + "/api/presets/import", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ raw, name, activate: false }),
|
||||
});
|
||||
const text = await res.text();
|
||||
let data = null;
|
||||
try { data = JSON.parse(text); } catch (e) { data = { raw: text.slice(0, 800) }; }
|
||||
if (!res.ok) {
|
||||
console.error("导入失败 HTTP " + res.status + ": " + JSON.stringify(data).slice(0, 800));
|
||||
process.exitCode = 1;
|
||||
} else {
|
||||
const p = data.preset || {};
|
||||
console.log("已导入: " + (p.name || name) + " id=" + (p.id || "?"));
|
||||
console.log("条目数: " + ((p.prompts || []).length || "?") + " 正文合计: " + ((p.prompts || []).reduce((n, x) => n + String(x.content || "").length, 0) || "?") + " 字");
|
||||
if (data.warnings && data.warnings.length) console.log("导入提示:\n - " + data.warnings.join("\n - "));
|
||||
}
|
||||
Reference in New Issue
Block a user