Refactor args for context/instruct select
| @@ -8526,7 +8526,7 @@ async function selectContextCallback(args, name) { | |||
| 8526 | } | 8526 | } |
| 8527 | 8527 | ||
| 8528 | const foundName = result[0].item; | 8528 | const foundName = result[0].item; |
| 8529 | selectContextPreset(foundName, quiet); | 8529 | selectContextPreset(foundName, { quiet: quiet }); |
| 8530 | return foundName; | 8530 | return foundName; |
| 8531 | } | 8531 | } |
| 8532 | 8532 | ||
| @@ -8546,7 +8546,7 @@ async function selectInstructCallback(args, name) { | |||
| 8546 | } | 8546 | } |
| 8547 | 8547 | ||
| 8548 | const foundName = result[0].item; | 8548 | const foundName = result[0].item; |
| 8549 | selectInstructPreset(foundName, quiet); | 8549 | selectInstructPreset(foundName, { quiet: quiet }); |
| 8550 | return foundName; | 8550 | return foundName; |
| 8551 | } | 8551 | } |
| 8552 | 8552 | ||
| @@ -130,13 +130,15 @@ function highlightDefaultPreset() { | |||
| 130 | /** | 130 | /** |
| 131 | * Select context template if not already selected. | 131 | * Select context template if not already selected. |
| 132 | * @param {string} preset Preset name. | 132 | * @param {string} preset Preset name. |
| 133 | * @param {boolean} quiet Suppress info message. | 133 | * @param {object} [options={}] Optional arguments. |
| 134 | * @param {boolean} [options.quiet=false] Suppress toast messages. | ||
| 135 | * @param {boolean} [options.isAuto=false] Is auto-select. | ||
| 134 | */ | 136 | */ |
| 135 | export function selectContextPreset(preset, quiet) { | 137 | export function selectContextPreset(preset, { quiet = false, isAuto = false } = {}) { |
| 136 | // If context template is not already selected, select it | 138 | // If context template is not already selected, select it |
| 137 | if (preset !== power_user.context.preset) { | 139 | if (preset !== power_user.context.preset) { |
| 138 | $('#context_presets').val(preset).trigger('change'); | 140 | $('#context_presets').val(preset).trigger('change'); |
| 139 | !quiet && toastr.info(`Context Template: preset "${preset}" auto-selected`); | 141 | !quiet && toastr.info(`Context Template: "${preset}" ${isAuto ? 'auto-' : ''}selected`); |
| 140 | } | 142 | } |
| 141 | 143 | ||
| 142 | // If instruct mode is disabled, enable it, except for default context template | 144 | // If instruct mode is disabled, enable it, except for default context template |
| @@ -152,13 +154,15 @@ export function selectContextPreset(preset, quiet) { | |||
| 152 | /** | 154 | /** |
| 153 | * Select instruct preset if not already selected. | 155 | * Select instruct preset if not already selected. |
| 154 | * @param {string} preset Preset name. | 156 | * @param {string} preset Preset name. |
| 155 | * @param {boolean} quiet Suppress info message. | 157 | * @param {object} [options={}] Optional arguments. |
| 158 | * @param {boolean} [options.quiet=false] Suppress toast messages. | ||
| 159 | * @param {boolean} [options.isAuto=false] Is auto-select. | ||
| 156 | */ | 160 | */ |
| 157 | export function selectInstructPreset(preset, quiet) { | 161 | export function selectInstructPreset(preset, { quiet = false, isAuto = false } = {}) { |
| 158 | // If instruct preset is not already selected, select it | 162 | // If instruct preset is not already selected, select it |
| 159 | if (preset !== power_user.instruct.preset) { | 163 | if (preset !== power_user.instruct.preset) { |
| 160 | $('#instruct_presets').val(preset).trigger('change'); | 164 | $('#instruct_presets').val(preset).trigger('change'); |
| 161 | !quiet && toastr.info(`Instruct Mode: template "${preset}" auto-selected`); | 165 | !quiet && toastr.info(`Instruct Template: "${preset}" ${isAuto ? 'auto-' : ''}selected`); |
| 162 | } | 166 | } |
| 163 | 167 | ||
| 164 | // If instruct mode is disabled, enable it | 168 | // If instruct mode is disabled, enable it |
| @@ -189,7 +193,7 @@ export function autoSelectInstructPreset(modelId) { | |||
| 189 | // If instruct preset matches the context template | 193 | // If instruct preset matches the context template |
| 190 | if (power_user.instruct.bind_to_context && instruct_preset.name === power_user.context.preset) { | 194 | if (power_user.instruct.bind_to_context && instruct_preset.name === power_user.context.preset) { |
| 191 | foundMatch = true; | 195 | foundMatch = true; |
| 192 | selectInstructPreset(instruct_preset.name); | 196 | selectInstructPreset(instruct_preset.name, { isAuto: true }); |
| 193 | break; | 197 | break; |
| 194 | } | 198 | } |
| 195 | } | 199 | } |
| @@ -203,7 +207,7 @@ export function autoSelectInstructPreset(modelId) { | |||
| 203 | 207 | ||
| 204 | // Stop on first match so it won't cycle back and forth between presets if multiple regexes match | 208 | // Stop on first match so it won't cycle back and forth between presets if multiple regexes match |
| 205 | if (regex instanceof RegExp && regex.test(modelId)) { | 209 | if (regex instanceof RegExp && regex.test(modelId)) { |
| 206 | selectInstructPreset(preset.name); | 210 | selectInstructPreset(preset.name, { isAuto: true }); |
| 207 | 211 | ||
| 208 | return true; | 212 | return true; |
| 209 | } | 213 | } |
| @@ -541,13 +545,13 @@ function selectMatchingContextTemplate(name) { | |||
| 541 | // If context template matches the instruct preset | 545 | // If context template matches the instruct preset |
| 542 | if (context_preset.name === name) { | 546 | if (context_preset.name === name) { |
| 543 | foundMatch = true; | 547 | foundMatch = true; |
| 544 | selectContextPreset(context_preset.name); | 548 | selectContextPreset(context_preset.name, { isAuto: true }); |
| 545 | break; | 549 | break; |
| 546 | } | 550 | } |
| 547 | } | 551 | } |
| 548 | if (!foundMatch) { | 552 | if (!foundMatch) { |
| 549 | // If no match was found, select default context preset | 553 | // If no match was found, select default context preset |
| 550 | selectContextPreset(power_user.default_context); | 554 | selectContextPreset(power_user.default_context, { isAuto: true }); |
| 551 | } | 555 | } |
| 552 | } | 556 | } |
| 553 | 557 | ||
| @@ -1798,7 +1798,7 @@ async function loadContextSettings() { | |||
| 1798 | for (const instruct_preset of instruct_presets) { | 1798 | for (const instruct_preset of instruct_presets) { |
| 1799 | // If instruct preset matches the context template | 1799 | // If instruct preset matches the context template |
| 1800 | if (instruct_preset.name === name) { | 1800 | if (instruct_preset.name === name) { |
| 1801 | selectInstructPreset(instruct_preset.name); | 1801 | selectInstructPreset(instruct_preset.name, { isAuto: true }); |
| 1802 | break; | 1802 | break; |
| 1803 | } | 1803 | } |
| 1804 | } | 1804 | } |