Merge pull request #3916 from SillyTavern/fix-instruct-regex

Check instruct activation regex before selecting context template
This commit is contained in:
Cohee
2025-04-26 14:25:35 +03:00
committed by GitHub

View File

@@ -208,16 +208,7 @@ export function autoSelectInstructPreset(modelId) {
// Select matching instruct preset
let foundMatch = false;
for (const instruct_preset of instruct_presets) {
// If instruct preset matches the context template
if (power_user.instruct.bind_to_context && instruct_preset.name === power_user.context.preset) {
foundMatch = true;
selectInstructPreset(instruct_preset.name, { isAuto: true });
break;
}
}
// If no match was found, auto-select instruct preset
if (!foundMatch) {
for (const preset of instruct_presets) {
// If activation regex is set, check if it matches the model id
if (preset.activation_regex) {
@@ -227,8 +218,8 @@ export function autoSelectInstructPreset(modelId) {
// Stop on first match so it won't cycle back and forth between presets if multiple regexes match
if (regex instanceof RegExp && regex.test(modelId)) {
selectInstructPreset(preset.name, { isAuto: true });
return true;
foundMatch = true;
break;
}
} catch {
// If regex is invalid, ignore it
@@ -236,9 +227,20 @@ export function autoSelectInstructPreset(modelId) {
}
}
}
// If no match was found, auto-select instruct preset
if (!foundMatch && power_user.instruct.bind_to_context) {
for (const instruct_preset of instruct_presets) {
// If instruct preset matches the context template
if (instruct_preset.name === power_user.context.preset) {
selectInstructPreset(instruct_preset.name, { isAuto: true });
foundMatch = true;
break;
}
}
}
return false;
return foundMatch;
}
/**