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

View File

@ -151,19 +151,20 @@ export function selectContextPreset(preset) {
/**
* Select instruct preset if not already selected.
* @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 (preset !== power_user.instruct.preset) {
$('#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 (!power_user.instruct.enabled) {
power_user.instruct.enabled = true;
$('#instruct_enabled').prop('checked', true).trigger('change');
toastr.info('Instruct Mode enabled');
!quiet && toastr.info('Instruct Mode enabled');
}
saveSettingsDebounced();

View File

@ -1477,6 +1477,15 @@ export function initDefaultSlashCommands() {
name: 'model',
callback: modelCallback,
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: [
SlashCommandArgument.fromProps({
description: 'model name',
@ -3382,11 +3391,11 @@ function getModelOptions() {
/**
* Sets a model for the current API.
* @param {object} _ Unused
* @param {object} args Named arguments
* @param {string} model New model name
* @returns {string} New or existing model name
*/
function modelCallback(_, model) {
function modelCallback(args, model) {
const { control: modelSelectControl, options } = getModelOptions();
// If no model was found, the reason was already logged, we just return here
@ -3426,7 +3435,8 @@ function modelCallback(_, model) {
if (newSelectedOption) {
modelSelectControl.value = newSelectedOption.value;
$(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;
} else {
toastr.warning(`No model found with name "${model}"`);