Add quiet args to /instruct and /model

This commit is contained in:
Cohee 2024-09-06 23:09:06 +03:00
parent b0b9558a6c
commit c68b344b60
3 changed files with 29 additions and 8 deletions

View File

@ -8522,7 +8522,7 @@ async function selectContextCallback(_, name) {
return foundName; return foundName;
} }
async function selectInstructCallback(_, name) { async function selectInstructCallback(args, name) {
if (!name) { if (!name) {
return power_user.instruct.preset; return power_user.instruct.preset;
} }
@ -8536,8 +8536,9 @@ async function selectInstructCallback(_, name) {
return ''; return '';
} }
const quiet = isTrueBoolean(args?.quiet);
const foundName = result[0].item; const foundName = result[0].item;
selectInstructPreset(foundName); selectInstructPreset(foundName, quiet);
return foundName; return foundName;
} }
@ -9216,6 +9217,15 @@ jQuery(async function () {
name: 'instruct', name: 'instruct',
callback: selectInstructCallback, callback: selectInstructCallback,
returns: 'current template', returns: 'current template',
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: 'instruct template name', description: 'instruct template name',

View File

@ -151,19 +151,20 @@ export function selectContextPreset(preset) {
/** /**
* 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.
*/ */
export function selectInstructPreset(preset) { export function selectInstructPreset(preset, quiet) {
// 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');
toastr.info(`Instruct Mode: template "${preset}" auto-selected`); !quiet && toastr.info(`Instruct Mode: template "${preset}" auto-selected`);
} }
// If instruct mode is disabled, enable it // If instruct mode is disabled, enable it
if (!power_user.instruct.enabled) { if (!power_user.instruct.enabled) {
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();

View File

@ -1477,6 +1477,15 @@ export function initDefaultSlashCommands() {
name: 'model', name: 'model',
callback: modelCallback, callback: modelCallback,
returns: 'current model', returns: 'current model',
namedArgumentList: [
SlashCommandNamedArgument.fromProps({
name: 'quiet',
description: 'suppress the toast message on model change',
typeList: [ARGUMENT_TYPE.BOOLEAN],
defaultValue: 'false',
enumList: commonEnumProviders.boolean('trueFalse')(),
}),
],
unnamedArgumentList: [ unnamedArgumentList: [
SlashCommandArgument.fromProps({ SlashCommandArgument.fromProps({
description: 'model name', description: 'model name',
@ -3382,11 +3391,11 @@ function getModelOptions() {
/** /**
* Sets a model for the current API. * Sets a model for the current API.
* @param {object} _ Unused * @param {object} args Named arguments
* @param {string} model New model name * @param {string} model New model name
* @returns {string} New or existing model name * @returns {string} New or existing model name
*/ */
function modelCallback(_, model) { function modelCallback(args, model) {
const { control: modelSelectControl, options } = getModelOptions(); const { control: modelSelectControl, options } = getModelOptions();
// If no model was found, the reason was already logged, we just return here // If no model was found, the reason was already logged, we just return here
@ -3426,7 +3435,8 @@ function modelCallback(_, model) {
if (newSelectedOption) { if (newSelectedOption) {
modelSelectControl.value = newSelectedOption.value; modelSelectControl.value = newSelectedOption.value;
$(modelSelectControl).trigger('change'); $(modelSelectControl).trigger('change');
toastr.success(`Model set to "${newSelectedOption.text}"`); const quiet = isTrueBoolean(args?.quiet);
!quiet && toastr.success(`Model set to "${newSelectedOption.text}"`);
return newSelectedOption.value; return newSelectedOption.value;
} else { } else {
toastr.warning(`No model found with name "${model}"`); toastr.warning(`No model found with name "${model}"`);