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