Add custom openai compatible to /api-url

f1739eaa70e63c77e95fa7ad43431e7fa998d438

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +27 -3Showing whitespace changes
public/script.js+27 -3
@@ -8528,9 +8528,30 @@ async function connectAPISlash(_, text) {
8528 * @param {string?} [args.api=null] - the API name to set/get the URL for8528 * @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 setting8529 * @param {string?} [args.connect=true] - whether to connect to the API after setting
8530 * @param {string} url - the API URL to set8530 * @param {string} url - the API URL to set
8531 * @returns {string}8531 * @returns {Promise<string>}
8532 */8532 */
8533function setApiUrlCallback({ api = null, connect = 'true' }, url) {8533async 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 command8555 // 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.`);
@@ -9059,7 +9080,10 @@ jQuery(async function () {
9059 name: 'api',9080 name: 'api',
9060 description: 'API to set/get the URL for - if not provided, current API is used',9081 description: 'API to set/get the URL for - if not provided, current API is used',
9061 typeList: [ARGUMENT_TYPE.STRING],9082 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 ],
9063 }),9087 }),
9064 SlashCommandNamedArgument.fromProps({9088 SlashCommandNamedArgument.fromProps({
9065 name: 'connect',9089 name: 'connect',