Add quiet argument to /api-url
| @@ -1616,6 +1616,13 @@ export function initDefaultSlashCommands() { | ||
| 1616 | 1616 | defaultValue: 'true', |
| 1617 | 1617 | enumList: commonEnumProviders.boolean('trueFalse')(), |
| 1618 | 1618 | }), |
| 1619 | + SlashCommandNamedArgument.fromProps({ | |
| 1620 | + name: 'quiet', | |
| 1621 | + description: 'suppress the toast message on API change', | |
| 1622 | + typeList: [ARGUMENT_TYPE.BOOLEAN], | |
| 1623 | + defaultValue: 'false', | |
| 1624 | + enumList: commonEnumProviders.boolean('trueFalse')(), | |
| 1625 | + }), | |
| 1619 | 1626 | ], |
| 1620 | 1627 | unnamedArgumentList: [ |
| 1621 | 1628 | SlashCommandArgument.fromProps({ |
| @@ -3577,10 +3584,12 @@ function setPromptEntryCallback(args, targetState) { | ||
| 3577 | 3584 | * @param {object} args - named args |
| 3578 | 3585 | * @param {string?} [args.api=null] - the API name to set/get the URL for |
| 3579 | 3586 | * @param {string?} [args.connect=true] - whether to connect to the API after setting |
| 3587 | + * @param {string?} [args.quiet=false] - whether to suppress toasts | |
| 3580 | 3588 | * @param {string} url - the API URL to set |
| 3581 | 3589 | * @returns {Promise<string>} |
| 3582 | 3590 | */ |
| 3583 | 3591 | async function setApiUrlCallback({ api = null, connect = 'true', quiet = 'false' }, url) { |
| 3592 | + const isQuiet = isTrueBoolean(quiet); | |
| 3584 | 3593 | const autoConnect = isTrueBoolean(connect); |
| 3585 | 3594 | |
| 3586 | 3595 | // Special handling for Chat Completion Custom OpenAI compatible, that one can also support API url handling |
| @@ -3629,22 +3638,26 @@ async function setApiUrlCallback({ api = null, connect = 'true' }, url) { | ||
| 3629 | 3638 | |
| 3630 | 3639 | // Do some checks and get the api type we are targeting with this command |
| 3631 | 3640 | if (api && !Object.values(textgen_types).includes(api)) { |
| 3632 | 3641 | !isQuiet && toastr.warning(`API '${api}' is not a valid text_gen API.`); |
| 3633 | 3642 | return ''; |
| 3634 | 3643 | } |
| 3635 | 3644 | if (!api && !Object.values(textgen_types).includes(textgenerationwebui_settings.type)) { |
| 3636 | 3645 | !isQuiet && toastr.warning(`API '${textgenerationwebui_settings.type}' is not a valid text_gen API.`); |
| 3646 | + return ''; | |
| 3647 | + } | |
| 3648 | + if (!api && main_api !== 'textgenerationwebui') { | |
| 3649 | + !isQuiet && toastr.warning(`API type '${main_api}' does not support setting the server URL.`); | |
| 3637 | 3650 | return ''; |
| 3638 | 3651 | } |
| 3639 | 3652 | if (api && url && autoConnect && api !== textgenerationwebui_settings.type) { |
| 3640 | 3653 | !isQuiet && toastr.warning(`API '${api}' is not the currently selected API, so we cannot do an auto-connect. Consider switching to it via /api beforehand.`); |
| 3641 | 3654 | return ''; |
| 3642 | 3655 | } |
| 3643 | 3656 | const type = api || textgenerationwebui_settings.type; |
| 3644 | 3657 | |
| 3645 | 3658 | const inputSelector = SERVER_INPUTS[type]; |
| 3646 | 3659 | if (!inputSelector) { |
| 3647 | 3660 | !isQuiet && toastr.warning(`API '${type}' does not have a server url input.`); |
| 3648 | 3661 | return ''; |
| 3649 | 3662 | } |
| 3650 | 3663 | |