| 8528 | * @param {string?} [args.api=null] - the API name to set/get the URL for | 8528 | * @param {string?} [args.api=null] - the API name to set/get the URL for |
| 8529 | * @param {string?} [args.connect=true] - whether to connect to the API after setting | 8529 | * @param {string?} [args.connect=true] - whether to connect to the API after setting |
| 8530 | * @param {string} url - the API URL to set | 8530 | * @param {string} url - the API URL to set |
| 8531 | * @returns {string} | 8531 | * @returns {Promise<string>} |
| 8532 | */ | 8532 | */ |
| 8533 | function setApiUrlCallback({ api = null, connect = 'true' }, url) { | 8533 | async function setApiUrlCallback({ api = null, connect = 'true' }, url) { |
| | 8534 | // Special handling for Chat Completion Custom OpenAI compatible, that one can also support API url handling |
| | 8535 | const isCurrentlyCustomOpenai = main_api === 'openai' && oai_settings.chat_completion_source === chat_completion_sources.CUSTOM; |
| | 8536 | if (api === chat_completion_sources.CUSTOM || (!api && isCurrentlyCustomOpenai)) { |
| | 8537 | if (url && !isCurrentlyCustomOpenai) { |
| | 8538 | toastr.warning(`Custom OpenAI API is not the currently selected API, so we cannot do an auto-connect. Consider switching to it via /api beforehand.`); |
| | 8539 | return ''; |
| | 8540 | } |
| | 8541 | |
| | 8542 | if (!url) { |
| | 8543 | return oai_settings.custom_url ?? ''; |
| | 8544 | } |
| | 8545 | |
| | 8546 | $('#custom_api_url_text').val(url).trigger('input'); |
| | 8547 | |
| | 8548 | if (isTrueBoolean(connect)) { |
| | 8549 | $('#api_button_openai').trigger('click'); |
| | 8550 | } |
| | 8551 | |
| | 8552 | return url; |
| | 8553 | } |
| | 8554 | |
| 8534 | // Do some checks and get the api type we are targeting with this command | 8555 | // Do some checks and get the api type we are targeting with this command |
| 8535 | if (api && !Object.values(textgen_types).includes(api)) { | 8556 | if (api && !Object.values(textgen_types).includes(api)) { |
| 8536 | toastr.warning(`API '${api}' is not a valid text_gen API.`); | 8557 | toastr.warning(`API '${api}' is not a valid text_gen API.`); |