mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Check instruct activation regex before selecting bound context template match
This commit is contained in:
@ -208,37 +208,39 @@ export function autoSelectInstructPreset(modelId) {
|
|||||||
|
|
||||||
// Select matching instruct preset
|
// Select matching instruct preset
|
||||||
let foundMatch = false;
|
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) {
|
|
||||||
try {
|
|
||||||
const regex = regexFromString(preset.activation_regex);
|
|
||||||
|
|
||||||
// Stop on first match so it won't cycle back and forth between presets if multiple regexes match
|
for (const preset of instruct_presets) {
|
||||||
if (regex instanceof RegExp && regex.test(modelId)) {
|
// If activation regex is set, check if it matches the model id
|
||||||
selectInstructPreset(preset.name, { isAuto: true });
|
if (preset.activation_regex) {
|
||||||
|
try {
|
||||||
|
const regex = regexFromString(preset.activation_regex);
|
||||||
|
|
||||||
return true;
|
// 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)) {
|
||||||
} catch {
|
selectInstructPreset(preset.name, { isAuto: true });
|
||||||
// If regex is invalid, ignore it
|
foundMatch = true;
|
||||||
console.warn(`Invalid instruct activation regex in preset "${preset.name}"`);
|
break;
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
// If regex is invalid, ignore it
|
||||||
|
console.warn(`Invalid instruct activation regex in preset "${preset.name}"`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
// 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 foundMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user