Extend quiet effect in /model
| @@ -1532,7 +1532,7 @@ export function initDefaultSlashCommands() { | |||
| 1532 | SlashCommandArgument.fromProps({ | 1532 | SlashCommandArgument.fromProps({ |
| 1533 | description: 'model name', | 1533 | description: 'model name', |
| 1534 | typeList: [ARGUMENT_TYPE.STRING], | 1534 | typeList: [ARGUMENT_TYPE.STRING], |
| 1535 | enumProvider: () => getModelOptions()?.options.map(option => new SlashCommandEnumValue(option.value, option.value !== option.text ? option.text : null)), | 1535 | enumProvider: () => getModelOptions(true)?.options?.map(option => new SlashCommandEnumValue(option.value, option.value !== option.text ? option.text : null)) ?? [], |
| 1536 | }), | 1536 | }), |
| 1537 | ], | 1537 | ], |
| 1538 | helpString: 'Sets the model for the current API. Gets the current model name if no argument is provided.', | 1538 | 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) { | |||
| 3383 | 3383 | ||
| 3384 | /** | 3384 | /** |
| 3385 | * Retrieves the available model options based on the currently selected main API and its subtype | 3385 | * Retrieves the available model options based on the currently selected main API and its subtype |
| 3386 | * @param {boolean} quiet - Whether to suppress toasts | ||
| 3386 | * | 3387 | * |
| 3387 | * @returns {{control: HTMLSelectElement, options: HTMLOptionElement[]}?} An array of objects representing the available model options, or null if not supported | 3388 | * @returns {{control: HTMLSelectElement, options: HTMLOptionElement[]}?} An array of objects representing the available model options, or null if not supported |
| 3388 | */ | 3389 | */ |
| 3389 | function getModelOptions() { | 3390 | function getModelOptions(quiet) { |
| 3391 | const nullResult = { control: null, options: null }; | ||
| 3390 | const modelSelectMap = [ | 3392 | const modelSelectMap = [ |
| 3391 | { id: 'model_togetherai_select', api: 'textgenerationwebui', type: textgen_types.TOGETHERAI }, | 3393 | { id: 'model_togetherai_select', api: 'textgenerationwebui', type: textgen_types.TOGETHERAI }, |
| 3392 | { id: 'openrouter_model', api: 'textgenerationwebui', type: textgen_types.OPENROUTER }, | 3394 | { id: 'openrouter_model', api: 'textgenerationwebui', type: textgen_types.OPENROUTER }, |
| @@ -3420,7 +3422,7 @@ function getModelOptions() { | |||
| 3420 | case 'openai': | 3422 | case 'openai': |
| 3421 | return oai_settings.chat_completion_source; | 3423 | return oai_settings.chat_completion_source; |
| 3422 | default: | 3424 | default: |
| 3423 | return null; | 3425 | return nullResult; |
| 3424 | } | 3426 | } |
| 3425 | } | 3427 | } |
| 3426 | 3428 | ||
| @@ -3428,15 +3430,15 @@ function getModelOptions() { | |||
| 3428 | const modelSelectItem = modelSelectMap.find(x => x.api == main_api && x.type == apiSubType)?.id; | 3430 | const modelSelectItem = modelSelectMap.find(x => x.api == main_api && x.type == apiSubType)?.id; |
| 3429 | 3431 | ||
| 3430 | if (!modelSelectItem) { | 3432 | if (!modelSelectItem) { |
| 3431 | toastr.info('Setting a model for your API is not supported or not implemented yet.'); | 3433 | !quiet && toastr.info('Setting a model for your API is not supported or not implemented yet.'); |
| 3432 | return null; | 3434 | return nullResult; |
| 3433 | } | 3435 | } |
| 3434 | 3436 | ||
| 3435 | const modelSelectControl = document.getElementById(modelSelectItem); | 3437 | const modelSelectControl = document.getElementById(modelSelectItem); |
| 3436 | 3438 | ||
| 3437 | if (!(modelSelectControl instanceof HTMLSelectElement)) { | 3439 | if (!(modelSelectControl instanceof HTMLSelectElement)) { |
| 3438 | toastr.error(`Model select control not found: ${main_api}[${apiSubType}]`); | 3440 | !quiet && toastr.error(`Model select control not found: ${main_api}[${apiSubType}]`); |
| 3439 | return null; | 3441 | return nullResult; |
| 3440 | } | 3442 | } |
| 3441 | 3443 | ||
| 3442 | const options = Array.from(modelSelectControl.options); | 3444 | const options = Array.from(modelSelectControl.options); |
| @@ -3450,7 +3452,8 @@ function getModelOptions() { | |||
| 3450 | * @returns {string} New or existing model name | 3452 | * @returns {string} New or existing model name |
| 3451 | */ | 3453 | */ |
| 3452 | function modelCallback(args, model) { | 3454 | function modelCallback(args, model) { |
| 3453 | const { control: modelSelectControl, options } = getModelOptions(); | 3455 | const quiet = isTrueBoolean(args?.quiet); |
| 3456 | const { control: modelSelectControl, options } = getModelOptions(quiet); | ||
| 3454 | 3457 | ||
| 3455 | // If no model was found, the reason was already logged, we just return here | 3458 | // If no model was found, the reason was already logged, we just return here |
| 3456 | if (options === null) { | 3459 | if (options === null) { |
| @@ -3458,7 +3461,7 @@ function modelCallback(args, model) { | |||
| 3458 | } | 3461 | } |
| 3459 | 3462 | ||
| 3460 | if (!options.length) { | 3463 | if (!options.length) { |
| 3461 | toastr.warning('No model options found. Check your API settings.'); | 3464 | !quiet && toastr.warning('No model options found. Check your API settings.'); |
| 3462 | return ''; | 3465 | return ''; |
| 3463 | } | 3466 | } |
| 3464 | 3467 | ||
| @@ -3489,11 +3492,10 @@ function modelCallback(args, model) { | |||
| 3489 | if (newSelectedOption) { | 3492 | if (newSelectedOption) { |
| 3490 | modelSelectControl.value = newSelectedOption.value; | 3493 | modelSelectControl.value = newSelectedOption.value; |
| 3491 | $(modelSelectControl).trigger('change'); | 3494 | $(modelSelectControl).trigger('change'); |
| 3492 | const quiet = isTrueBoolean(args?.quiet); | ||
| 3493 | !quiet && toastr.success(`Model set to "${newSelectedOption.text}"`); | 3495 | !quiet && toastr.success(`Model set to "${newSelectedOption.text}"`); |
| 3494 | return newSelectedOption.value; | 3496 | return newSelectedOption.value; |
| 3495 | } else { | 3497 | } else { |
| 3496 | toastr.warning(`No model found with name "${model}"`); | 3498 | !quiet && toastr.warning(`No model found with name "${model}"`); |
| 3497 | return ''; | 3499 | return ''; |
| 3498 | } | 3500 | } |
| 3499 | } | 3501 | } |