- 装配只认 prompt_order.enabled;squash_system_messages 只合并相邻 system(新增 system 档,连接符按酒馆用单换行)
- 包装层:new_chat_prompt、示例对话(new_example_chat_prompt + <START> 切段 + name)、角色卡三块与 personality_format/scenario_format、{{user}}/{{char}} 取值、任务契约并进预设条目
- 工具协议:按 ToolBindings / 伪工具协议数据声明真 tools(presetToolPolicy=preset),工具描述用到的条目不再重复作为消息发出
- 正则:promptOnly 作用于对话历史(含 depth 过滤)、写入时脚本改写回复;{{//}} 注释按配平扫描
- tools/st-request-diff:真假上游抓包对比工具、三份预设的机制结论与实测报告
76 lines
2.3 KiB
TypeScript
76 lines
2.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { importSillyTavernPreset } from "../src/preset/importer.js";
|
|
import { assemblePresetProbe, runPresetProbe } from "../src/preset/probe.js";
|
|
|
|
function linuxLikePreset() {
|
|
return importSillyTavernPreset(
|
|
{
|
|
prompts: [
|
|
{ identifier: "main", name: "主体", role: "system", content: "{{user}} 写" },
|
|
{ identifier: "chatHistory", name: "历史", role: "system", content: "", marker: true },
|
|
{
|
|
identifier: "guide",
|
|
name: "工具说明",
|
|
role: "system",
|
|
content: "active_interface = %TOOL_NAME%\nstream_target = display_stream",
|
|
},
|
|
],
|
|
prompt_order: [
|
|
{
|
|
character_id: 100001,
|
|
order: [
|
|
{ identifier: "main", enabled: true },
|
|
{ identifier: "chatHistory", enabled: true },
|
|
{ identifier: "guide", enabled: true },
|
|
],
|
|
},
|
|
],
|
|
squash_system_messages: true,
|
|
},
|
|
{ name: "linux-like" },
|
|
).preset;
|
|
}
|
|
|
|
describe("probe 展示实际发出的形态", () => {
|
|
it("reports the squash mode and the tool plan", async () => {
|
|
const preset = linuxLikePreset();
|
|
const result = await runPresetProbe({
|
|
preset,
|
|
input: { message: "继续" },
|
|
options: { charName: "长夜行" },
|
|
});
|
|
|
|
expect(result.squashMode).toBe("system");
|
|
expect(result.toolPlan?.present).toBe(true);
|
|
expect(result.toolPlan?.payloadFields).toContain("display_stream");
|
|
});
|
|
|
|
it("expands {{user}} and drops entries that become empty", () => {
|
|
const preset = linuxLikePreset();
|
|
const messages = assemblePresetProbe(
|
|
preset,
|
|
{ message: "继续" },
|
|
{ charName: "长夜行" },
|
|
);
|
|
const all = messages.map((m) => m.content).join("\n");
|
|
expect(all).not.toContain("{{user}}");
|
|
// 换成当前人设名(探针缺省用选中人设)
|
|
expect(all).toMatch(/\S+ 写/);
|
|
});
|
|
|
|
it("merges adjacent system messages in the displayed sequence", () => {
|
|
const preset = linuxLikePreset();
|
|
const messages = assemblePresetProbe(
|
|
preset,
|
|
{ message: "继续" },
|
|
{ squash: "merge" },
|
|
);
|
|
const roles = messages.map((m) => m.role);
|
|
for (let i = 1; i < roles.length; i++) {
|
|
if (roles[i] === "system") {
|
|
expect(roles[i - 1]).not.toBe("system");
|
|
}
|
|
}
|
|
});
|
|
});
|