mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-01-31 11:35:37 +01:00
Refactor args for context/instruct select
This commit is contained in:
parent
44ddec88fe
commit
4ba99412af
@ -8526,7 +8526,7 @@ async function selectContextCallback(args, name) {
|
||||
}
|
||||
|
||||
const foundName = result[0].item;
|
||||
selectContextPreset(foundName, quiet);
|
||||
selectContextPreset(foundName, { quiet: quiet });
|
||||
return foundName;
|
||||
}
|
||||
|
||||
@ -8546,7 +8546,7 @@ async function selectInstructCallback(args, name) {
|
||||
}
|
||||
|
||||
const foundName = result[0].item;
|
||||
selectInstructPreset(foundName, quiet);
|
||||
selectInstructPreset(foundName, { quiet: quiet });
|
||||
return foundName;
|
||||
}
|
||||
|
||||
|
@ -130,13 +130,15 @@ function highlightDefaultPreset() {
|
||||
/**
|
||||
* Select context template if not already selected.
|
||||
* @param {string} preset Preset name.
|
||||
* @param {boolean} quiet Suppress info message.
|
||||
* @param {object} [options={}] Optional arguments.
|
||||
* @param {boolean} [options.quiet=false] Suppress toast messages.
|
||||
* @param {boolean} [options.isAuto=false] Is auto-select.
|
||||
*/
|
||||
export function selectContextPreset(preset, quiet) {
|
||||
export function selectContextPreset(preset, { quiet = false, isAuto = false } = {}) {
|
||||
// If context template is not already selected, select it
|
||||
if (preset !== power_user.context.preset) {
|
||||
$('#context_presets').val(preset).trigger('change');
|
||||
!quiet && toastr.info(`Context Template: preset "${preset}" auto-selected`);
|
||||
!quiet && toastr.info(`Context Template: "${preset}" ${isAuto ? 'auto-' : ''}selected`);
|
||||
}
|
||||
|
||||
// If instruct mode is disabled, enable it, except for default context template
|
||||
@ -152,13 +154,15 @@ export function selectContextPreset(preset, quiet) {
|
||||
/**
|
||||
* Select instruct preset if not already selected.
|
||||
* @param {string} preset Preset name.
|
||||
* @param {boolean} quiet Suppress info message.
|
||||
* @param {object} [options={}] Optional arguments.
|
||||
* @param {boolean} [options.quiet=false] Suppress toast messages.
|
||||
* @param {boolean} [options.isAuto=false] Is auto-select.
|
||||
*/
|
||||
export function selectInstructPreset(preset, quiet) {
|
||||
export function selectInstructPreset(preset, { quiet = false, isAuto = false } = {}) {
|
||||
// If instruct preset is not already selected, select it
|
||||
if (preset !== power_user.instruct.preset) {
|
||||
$('#instruct_presets').val(preset).trigger('change');
|
||||
!quiet && toastr.info(`Instruct Mode: template "${preset}" auto-selected`);
|
||||
!quiet && toastr.info(`Instruct Template: "${preset}" ${isAuto ? 'auto-' : ''}selected`);
|
||||
}
|
||||
|
||||
// If instruct mode is disabled, enable it
|
||||
@ -189,7 +193,7 @@ export function autoSelectInstructPreset(modelId) {
|
||||
// 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);
|
||||
selectInstructPreset(instruct_preset.name, { isAuto: true });
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -203,7 +207,7 @@ 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);
|
||||
selectInstructPreset(preset.name, { isAuto: true });
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -541,13 +545,13 @@ function selectMatchingContextTemplate(name) {
|
||||
// If context template matches the instruct preset
|
||||
if (context_preset.name === name) {
|
||||
foundMatch = true;
|
||||
selectContextPreset(context_preset.name);
|
||||
selectContextPreset(context_preset.name, { isAuto: true });
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundMatch) {
|
||||
// If no match was found, select default context preset
|
||||
selectContextPreset(power_user.default_context);
|
||||
selectContextPreset(power_user.default_context, { isAuto: true });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1798,7 +1798,7 @@ async function loadContextSettings() {
|
||||
for (const instruct_preset of instruct_presets) {
|
||||
// If instruct preset matches the context template
|
||||
if (instruct_preset.name === name) {
|
||||
selectInstructPreset(instruct_preset.name);
|
||||
selectInstructPreset(instruct_preset.name, { isAuto: true });
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user