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
209 // Select matching instruct preset209 // Select matching instruct preset
210 let foundMatch = false;210 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) {
221 for (const preset of instruct_presets) {212 for (const preset of instruct_presets) {
222 // If activation regex is set, check if it matches the model id213 // If activation regex is set, check if it matches the model id
223 if (preset.activation_regex) {214 if (preset.activation_regex) {
@@ -227,8 +218,8 @@ export function autoSelectInstructPreset(modelId) {
227 // Stop on first match so it won't cycle back and forth between presets if multiple regexes match218 // Stop on first match so it won't cycle back and forth between presets if multiple regexes match
228 if (regex instanceof RegExp && regex.test(modelId)) {219 if (regex instanceof RegExp && regex.test(modelId)) {
229 selectInstructPreset(preset.name, { isAuto: true });220 selectInstructPreset(preset.name, { isAuto: true });
230221 foundMatch = true;
231 return true;222 break;
232 }223 }
233 } catch {224 } catch {
234 // If regex is invalid, ignore it225 // If regex is invalid, ignore it
@@ -236,9 +227,20 @@ export function autoSelectInstructPreset(modelId) {
236 }227 }
237 }228 }
238 }229 }
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 }
239 }241 }
240242
241 return false;243 return foundMatch;
242}244}
243245
244/**246/**