Fix task regex final input pipeline

This commit is contained in:
Youzini-afk
2026-04-05 00:30:54 +08:00
parent 1eeb6f05b5
commit 5cc33fabda
7 changed files with 412 additions and 51 deletions

View File

@@ -254,7 +254,8 @@ try {
assert.match(promptBuild.systemPrompt, /GOOD_RECENT/);
assert.match(JSON.stringify(promptBuild.executionMessages), /GOOD_CANDIDATE/);
assert.match(promptBuild.systemPrompt, /FINAL_GOOD/);
assert.match(promptBuild.systemPrompt, /FINAL_BAD/);
assert.doesNotMatch(promptBuild.systemPrompt, /FINAL_GOOD/);
assert.equal(
promptBuild.debug.mvu.sanitizedFields.some((entry) => entry.name === "userMessage"),
true,
@@ -454,6 +455,8 @@ try {
const payload = buildTaskLlmPayload(promptBuild, "unused fallback");
assert.equal(payload.systemPrompt, "");
assert.match(JSON.stringify(payload.promptMessages), /FINAL_BAD/);
assert.doesNotMatch(JSON.stringify(payload.promptMessages), /FINAL_GOOD/);
const result = await llm.callLLMForJSON({
systemPrompt: payload.systemPrompt,
userPrompt: payload.userPrompt,
@@ -466,6 +469,8 @@ try {
assert.deepEqual(result, { ok: true });
assert.equal(capturedBodies.length, 1);
assert.match(JSON.stringify(capturedBodies[0].messages), /FINAL_GOOD/);
assert.doesNotMatch(JSON.stringify(capturedBodies[0].messages), /FINAL_BAD/);
assert.doesNotMatch(
JSON.stringify(capturedBodies[0].messages),
/status_current_variable|updatevariable|StatusPlaceHolderImpl|stat_data|display_data|delta_data|get_message_variable/i,
@@ -478,6 +483,18 @@ try {
assert.ok(runtimePromptBuild);
assert.ok(runtimeLlmRequest);
assert.match(JSON.stringify(runtimeLlmRequest.messages), /FINAL_GOOD/);
assert.equal(runtimeLlmRequest.requestCleaning?.applied, true);
assert.equal(
runtimeLlmRequest.requestCleaning?.stages?.length > 0,
true,
);
assert.equal(
runtimeLlmRequest.requestCleaning?.stages?.every(
(entry) => entry.stage === "input.finalPrompt",
),
true,
);
assert.doesNotMatch(
JSON.stringify(runtimePromptBuild.executionMessages),
/status_current_variable|updatevariable|StatusPlaceHolderImpl|stat_data|display_data|delta_data|get_message_variable/i,

View File

@@ -365,6 +365,79 @@ try {
assert.equal(exactStageResult, "JSON");
assert.deepEqual(exactStageDebug.entries[0].appliedRules, []);
const legacyStageCompatibilitySettings = {
taskProfilesVersion: 1,
taskProfiles: {
extract: {
activeProfileId: "legacy-stage-compat",
profiles: [
{
id: "legacy-stage-compat",
taskType: "extract",
regex: {
enabled: true,
inheritStRegex: false,
sources: {
global: false,
preset: false,
character: false,
},
stages: {
input: true,
output: true,
"input.userMessage": false,
"input.recentMessages": false,
"input.candidateText": false,
"input.finalPrompt": false,
"output.rawResponse": false,
"output.beforeParse": false,
},
localRules: [
createRule("legacy-input-user", "/Alpha/g", "A1"),
createRule("legacy-output-raw", "/Omega/g", "O1", {
source: {
user_input: false,
ai_output: true,
},
}),
],
},
},
],
},
},
};
const legacyStageInputDebug = { entries: [] };
const legacyStageInputResult = applyTaskRegex(
legacyStageCompatibilitySettings,
"extract",
"input.userMessage",
"Alpha",
legacyStageInputDebug,
"user",
);
assert.equal(legacyStageInputResult, "A1");
assert.deepEqual(
legacyStageInputDebug.entries[0].appliedRules.map((item) => item.id),
["legacy-input-user"],
);
const legacyStageOutputDebug = { entries: [] };
const legacyStageOutputResult = applyTaskRegex(
legacyStageCompatibilitySettings,
"extract",
"output.rawResponse",
"Omega",
legacyStageOutputDebug,
"assistant",
);
assert.equal(legacyStageOutputResult, "O1");
assert.deepEqual(
legacyStageOutputDebug.entries[0].appliedRules.map((item) => item.id),
["legacy-output-raw"],
);
console.log("task-regex tests passed");
} finally {
if (originalSillyTavern === undefined) {