Add custom openai compatible to /api-url

f1739eaa70e63c77e95fa7ad43431e7fa998d438

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +27 -3Ignore whitespace
public/script.js+27 -3
@@ -8528,9 +8528,30 @@ async function connectAPISlash(_, text) {
85288528 * @param {string?} [args.api=null] - the API name to set/get the URL for
85298529 * @param {string?} [args.connect=true] - whether to connect to the API after setting
85308530 * @param {string} url - the API URL to set
85318531 * @returns {Promise<string>}
85328532 */
85338533async 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+
85348555 // Do some checks and get the api type we are targeting with this command
85358556 if (api && !Object.values(textgen_types).includes(api)) {
85368557 toastr.warning(`API '${api}' is not a valid text_gen API.`);
@@ -9059,7 +9080,10 @@ jQuery(async function () {
90599080 name: 'api',
90609081 description: 'API to set/get the URL for - if not provided, current API is used',
90619082 typeList: [ARGUMENT_TYPE.STRING],
9062- enumList: Object.values(textgen_types).map(api => new SlashCommandEnumValue(api, null, enumTypes.enum)),
9083+ enumList: [
9084+ new SlashCommandEnumValue('custom', 'custom openai compatible', enumTypes.getBasedOnIndex(uniqueAPIs.findIndex(x => x === 'openai')), 'O'),
9085+ ...Object.values(textgen_types).map(api => new SlashCommandEnumValue(api, null, enumTypes.getBasedOnIndex(uniqueAPIs.findIndex(x => x === 'textgenerationwebui')), 'T')),
9086+ ],
90639087 }),
90649088 SlashCommandNamedArgument.fromProps({
90659089 name: 'connect',