mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-12 10:00:36 +01:00
Add quiet arg to /context
This commit is contained in:
parent
4f5097915e
commit
97a2c4b2c7
@ -8503,22 +8503,23 @@ for (const chatCompletionSource of Object.values(chat_completion_sources)) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function selectContextCallback(_, name) {
|
async function selectContextCallback(args, name) {
|
||||||
if (!name) {
|
if (!name) {
|
||||||
return power_user.context.preset;
|
return power_user.context.preset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const quiet = isTrueBoolean(args?.quiet);
|
||||||
const contextNames = context_presets.map(preset => preset.name);
|
const contextNames = context_presets.map(preset => preset.name);
|
||||||
const fuse = new Fuse(contextNames);
|
const fuse = new Fuse(contextNames);
|
||||||
const result = fuse.search(name);
|
const result = fuse.search(name);
|
||||||
|
|
||||||
if (result.length === 0) {
|
if (result.length === 0) {
|
||||||
toastr.warning(`Context template "${name}" not found`);
|
!quiet && toastr.warning(`Context template "${name}" not found`);
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const foundName = result[0].item;
|
const foundName = result[0].item;
|
||||||
selectContextPreset(foundName);
|
selectContextPreset(foundName, quiet);
|
||||||
return foundName;
|
return foundName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8527,16 +8528,16 @@ async function selectInstructCallback(args, name) {
|
|||||||
return power_user.instruct.preset;
|
return power_user.instruct.preset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const quiet = isTrueBoolean(args?.quiet);
|
||||||
const instructNames = instruct_presets.map(preset => preset.name);
|
const instructNames = instruct_presets.map(preset => preset.name);
|
||||||
const fuse = new Fuse(instructNames);
|
const fuse = new Fuse(instructNames);
|
||||||
const result = fuse.search(name);
|
const result = fuse.search(name);
|
||||||
|
|
||||||
if (result.length === 0) {
|
if (result.length === 0) {
|
||||||
toastr.warning(`Instruct template "${name}" not found`);
|
!quiet && toastr.warning(`Instruct template "${name}" not found`);
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const quiet = isTrueBoolean(args?.quiet);
|
|
||||||
const foundName = result[0].item;
|
const foundName = result[0].item;
|
||||||
selectInstructPreset(foundName, quiet);
|
selectInstructPreset(foundName, quiet);
|
||||||
return foundName;
|
return foundName;
|
||||||
@ -9282,6 +9283,15 @@ jQuery(async function () {
|
|||||||
name: 'context',
|
name: 'context',
|
||||||
callback: selectContextCallback,
|
callback: selectContextCallback,
|
||||||
returns: 'template name',
|
returns: 'template name',
|
||||||
|
namedArgumentList: [
|
||||||
|
SlashCommandNamedArgument.fromProps({
|
||||||
|
name: 'quiet',
|
||||||
|
description: 'Suppress the toast message on template change',
|
||||||
|
typeList: [ARGUMENT_TYPE.BOOLEAN],
|
||||||
|
defaultValue: 'false',
|
||||||
|
enumList: commonEnumProviders.boolean('trueFalse')(),
|
||||||
|
}),
|
||||||
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
SlashCommandArgument.fromProps({
|
SlashCommandArgument.fromProps({
|
||||||
description: 'context template name',
|
description: 'context template name',
|
||||||
|
@ -130,19 +130,20 @@ 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.
|
||||||
*/
|
*/
|
||||||
export function selectContextPreset(preset) {
|
export function selectContextPreset(preset, quiet) {
|
||||||
// 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');
|
||||||
toastr.info(`Context Template: preset "${preset}" auto-selected`);
|
!quiet && toastr.info(`Context Template: preset "${preset}" 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
|
||||||
if (!power_user.instruct.enabled && preset !== power_user.default_context) {
|
if (!power_user.instruct.enabled && preset !== power_user.default_context) {
|
||||||
power_user.instruct.enabled = true;
|
power_user.instruct.enabled = true;
|
||||||
$('#instruct_enabled').prop('checked', true).trigger('change');
|
$('#instruct_enabled').prop('checked', true).trigger('change');
|
||||||
toastr.info('Instruct Mode enabled');
|
!quiet && toastr.info('Instruct Mode enabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user