mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Refactor args for context/instruct select
This commit is contained in:
@ -8526,7 +8526,7 @@ async function selectContextCallback(args, name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const foundName = result[0].item;
|
const foundName = result[0].item;
|
||||||
selectContextPreset(foundName, quiet);
|
selectContextPreset(foundName, { quiet: quiet });
|
||||||
return foundName;
|
return foundName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8546,7 +8546,7 @@ async function selectInstructCallback(args, name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const foundName = result[0].item;
|
const foundName = result[0].item;
|
||||||
selectInstructPreset(foundName, quiet);
|
selectInstructPreset(foundName, { quiet: quiet });
|
||||||
return foundName;
|
return foundName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,13 +130,15 @@ function highlightDefaultPreset() {
|
|||||||
/**
|
/**
|
||||||
* Select context template if not already selected.
|
* Select context template if not already selected.
|
||||||
* @param {string} preset Preset name.
|
* @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 context template is not already selected, select it
|
||||||
if (preset !== power_user.context.preset) {
|
if (preset !== power_user.context.preset) {
|
||||||
$('#context_presets').val(preset).trigger('change');
|
$('#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
|
// 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.
|
* Select instruct preset if not already selected.
|
||||||
* @param {string} preset Preset name.
|
* @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 instruct preset is not already selected, select it
|
||||||
if (preset !== power_user.instruct.preset) {
|
if (preset !== power_user.instruct.preset) {
|
||||||
$('#instruct_presets').val(preset).trigger('change');
|
$('#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
|
// If instruct mode is disabled, enable it
|
||||||
@ -189,7 +193,7 @@ export function autoSelectInstructPreset(modelId) {
|
|||||||
// If instruct preset matches the context template
|
// If instruct preset matches the context template
|
||||||
if (power_user.instruct.bind_to_context && instruct_preset.name === power_user.context.preset) {
|
if (power_user.instruct.bind_to_context && instruct_preset.name === power_user.context.preset) {
|
||||||
foundMatch = true;
|
foundMatch = true;
|
||||||
selectInstructPreset(instruct_preset.name);
|
selectInstructPreset(instruct_preset.name, { isAuto: true });
|
||||||
break;
|
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
|
// 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)) {
|
if (regex instanceof RegExp && regex.test(modelId)) {
|
||||||
selectInstructPreset(preset.name);
|
selectInstructPreset(preset.name, { isAuto: true });
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -541,13 +545,13 @@ function selectMatchingContextTemplate(name) {
|
|||||||
// If context template matches the instruct preset
|
// If context template matches the instruct preset
|
||||||
if (context_preset.name === name) {
|
if (context_preset.name === name) {
|
||||||
foundMatch = true;
|
foundMatch = true;
|
||||||
selectContextPreset(context_preset.name);
|
selectContextPreset(context_preset.name, { isAuto: true });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!foundMatch) {
|
if (!foundMatch) {
|
||||||
// If no match was found, select default context preset
|
// 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) {
|
for (const instruct_preset of instruct_presets) {
|
||||||
// If instruct preset matches the context template
|
// If instruct preset matches the context template
|
||||||
if (instruct_preset.name === name) {
|
if (instruct_preset.name === name) {
|
||||||
selectInstructPreset(instruct_preset.name);
|
selectInstructPreset(instruct_preset.name, { isAuto: true });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user