Add quiet argument to /api-url

ed115d4e11f182b632b292012afa1648ad0943f9

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

1 files changed, +18 -5Ignore whitespace
public/scripts/slash-commands.js+18 -5
@@ -1616,6 +1616,13 @@ export function initDefaultSlashCommands() {
16161616 defaultValue: 'true',
16171617 enumList: commonEnumProviders.boolean('trueFalse')(),
16181618 }),
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+ }),
16191626 ],
16201627 unnamedArgumentList: [
16211628 SlashCommandArgument.fromProps({
@@ -3577,10 +3584,12 @@ function setPromptEntryCallback(args, targetState) {
35773584 * @param {object} args - named args
35783585 * @param {string?} [args.api=null] - the API name to set/get the URL for
35793586 * @param {string?} [args.connect=true] - whether to connect to the API after setting
3587+ * @param {string?} [args.quiet=false] - whether to suppress toasts
35803588 * @param {string} url - the API URL to set
35813589 * @returns {Promise<string>}
35823590 */
35833591async function setApiUrlCallback({ api = null, connect = 'true', quiet = 'false' }, url) {
3592+ const isQuiet = isTrueBoolean(quiet);
35843593 const autoConnect = isTrueBoolean(connect);
35853594
35863595 // 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) {
36293638
36303639 // Do some checks and get the api type we are targeting with this command
36313640 if (api && !Object.values(textgen_types).includes(api)) {
36323641 !isQuiet && toastr.warning(`API '${api}' is not a valid text_gen API.`);
36333642 return '';
36343643 }
36353644 if (!api && !Object.values(textgen_types).includes(textgenerationwebui_settings.type)) {
36363645 !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.`);
36373650 return '';
36383651 }
36393652 if (api && url && autoConnect && api !== textgenerationwebui_settings.type) {
36403653 !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.`);
36413654 return '';
36423655 }
36433656 const type = api || textgenerationwebui_settings.type;
36443657
36453658 const inputSelector = SERVER_INPUTS[type];
36463659 if (!inputSelector) {
36473660 !isQuiet && toastr.warning(`API '${type}' does not have a server url input.`);
36483661 return '';
36493662 }
36503663