Extend quiet effect in /model

c77c3d8f37d976700c977dcc58632425785d6c14

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +13 -11Ignore whitespace
public/scripts/slash-commands.js+13 -11
@@ -1532,7 +1532,7 @@ export function initDefaultSlashCommands() {
15321532 SlashCommandArgument.fromProps({
15331533 description: 'model name',
15341534 typeList: [ARGUMENT_TYPE.STRING],
15351535 enumProvider: () => getModelOptions(true)?.options?.map(option => new SlashCommandEnumValue(option.value, option.value !== option.text ? option.text : null)) ?? [],
15361536 }),
15371537 ],
15381538 helpString: 'Sets the model for the current API. Gets the current model name if no argument is provided.',
@@ -3383,10 +3383,12 @@ function setBackgroundCallback(_, bg) {
33833383
33843384/**
33853385 * Retrieves the available model options based on the currently selected main API and its subtype
3386+ * @param {boolean} quiet - Whether to suppress toasts
33863387 *
33873388 * @returns {{control: HTMLSelectElement, options: HTMLOptionElement[]}?} An array of objects representing the available model options, or null if not supported
33883389 */
33893390function getModelOptions(quiet) {
3391+ const nullResult = { control: null, options: null };
33903392 const modelSelectMap = [
33913393 { id: 'model_togetherai_select', api: 'textgenerationwebui', type: textgen_types.TOGETHERAI },
33923394 { id: 'openrouter_model', api: 'textgenerationwebui', type: textgen_types.OPENROUTER },
@@ -3420,7 +3422,7 @@ function getModelOptions() {
34203422 case 'openai':
34213423 return oai_settings.chat_completion_source;
34223424 default:
34233425 return nullnullResult;
34243426 }
34253427 }
34263428
@@ -3428,15 +3430,15 @@ function getModelOptions() {
34283430 const modelSelectItem = modelSelectMap.find(x => x.api == main_api && x.type == apiSubType)?.id;
34293431
34303432 if (!modelSelectItem) {
34313433 !quiet && toastr.info('Setting a model for your API is not supported or not implemented yet.');
34323434 return nullnullResult;
34333435 }
34343436
34353437 const modelSelectControl = document.getElementById(modelSelectItem);
34363438
34373439 if (!(modelSelectControl instanceof HTMLSelectElement)) {
34383440 !quiet && toastr.error(`Model select control not found: ${main_api}[${apiSubType}]`);
34393441 return nullnullResult;
34403442 }
34413443
34423444 const options = Array.from(modelSelectControl.options);
@@ -3450,7 +3452,8 @@ function getModelOptions() {
34503452 * @returns {string} New or existing model name
34513453 */
34523454function modelCallback(args, model) {
34533455 const { control: modelSelectControl, options }quiet = getModelOptionsisTrueBoolean(args?.quiet);
3456+ const { control: modelSelectControl, options } = getModelOptions(quiet);
34543457
34553458 // If no model was found, the reason was already logged, we just return here
34563459 if (options === null) {
@@ -3458,7 +3461,7 @@ function modelCallback(args, model) {
34583461 }
34593462
34603463 if (!options.length) {
34613464 !quiet && toastr.warning('No model options found. Check your API settings.');
34623465 return '';
34633466 }
34643467
@@ -3489,11 +3492,10 @@ function modelCallback(args, model) {
34893492 if (newSelectedOption) {
34903493 modelSelectControl.value = newSelectedOption.value;
34913494 $(modelSelectControl).trigger('change');
3492- const quiet = isTrueBoolean(args?.quiet);
34933495 !quiet && toastr.success(`Model set to "${newSelectedOption.text}"`);
34943496 return newSelectedOption.value;
34953497 } else {
34963498 !quiet && toastr.warning(`No model found with name "${model}"`);
34973499 return '';
34983500 }
34993501}