Merge pull request #3916 from SillyTavern/fix-instruct-regex Check instruct activation regex before selecting context template

37c97db96980f63357aeca393cfa0d1d553de7b0

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
1 files changed, +15 -13Showing whitespace changes
public/scripts/instruct-mode.js+15 -13
@@ -208,16 +208,7 @@ export function autoSelectInstructPreset(modelId) {
208208
209209 // Select matching instruct preset
210210 let foundMatch = false;
211- for (const instruct_preset of instruct_presets) {
211+
212- // If instruct preset matches the context template
213- if (power_user.instruct.bind_to_context && instruct_preset.name === power_user.context.preset) {
214- foundMatch = true;
215- selectInstructPreset(instruct_preset.name, { isAuto: true });
216- break;
217- }
218- }
219- // If no match was found, auto-select instruct preset
220- if (!foundMatch) {
221212 for (const preset of instruct_presets) {
222213 // If activation regex is set, check if it matches the model id
223214 if (preset.activation_regex) {
@@ -227,8 +218,8 @@ export function autoSelectInstructPreset(modelId) {
227218 // Stop on first match so it won't cycle back and forth between presets if multiple regexes match
228219 if (regex instanceof RegExp && regex.test(modelId)) {
229220 selectInstructPreset(preset.name, { isAuto: true });
230-
221+ foundMatch = true;
231- return true;
222+ break;
232223 }
233224 } catch {
234225 // If regex is invalid, ignore it
@@ -236,9 +227,20 @@ export function autoSelectInstructPreset(modelId) {
236227 }
237228 }
238229 }
230+
231+ // If no match was found, auto-select instruct preset
232+ if (!foundMatch && power_user.instruct.bind_to_context) {
233+ for (const instruct_preset of instruct_presets) {
234+ // If instruct preset matches the context template
235+ if (instruct_preset.name === power_user.context.preset) {
236+ selectInstructPreset(instruct_preset.name, { isAuto: true });
237+ foundMatch = true;
238+ break;
239+ }
240+ }
239241 }
240242
241243 return falsefoundMatch;
242244}
243245
244246/**