Add support for Kobold Classic
| @@ -8392,6 +8392,9 @@ const CONNECT_API_MAP = { | ||
| 8392 | 8392 | }, |
| 8393 | 8393 | }; |
| 8394 | 8394 | |
| 8395 | +// Collect all unique API names in an array | |
| 8396 | +export const UNIQUE_APIS = [...new Set(Object.values(CONNECT_API_MAP).map(x => x.selected))]; | |
| 8397 | + | |
| 8395 | 8398 | // Fill connections map from textgen_types and chat_completion_sources |
| 8396 | 8399 | for (const textGenType of Object.values(textgen_types)) { |
| 8397 | 8400 | if (CONNECT_API_MAP[textGenType]) continue; |
| @@ -8966,9 +8969,6 @@ jQuery(async function () { | ||
| 8966 | 8969 | return ''; |
| 8967 | 8970 | } |
| 8968 | 8971 | |
| 8969 | - // Collect all unique API names in an array | |
| 8970 | - const uniqueAPIs = [...new Set(Object.values(CONNECT_API_MAP).map(x => x.selected))]; | |
| 8971 | - | |
| 8972 | 8972 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 8973 | 8973 | name: 'dupe', |
| 8974 | 8974 | callback: duplicateCharacter, |
| @@ -8983,7 +8983,7 @@ jQuery(async function () { | ||
| 8983 | 8983 | description: 'API to connect to', |
| 8984 | 8984 | typeList: [ARGUMENT_TYPE.STRING], |
| 8985 | 8985 | enumList: Object.entries(CONNECT_API_MAP).map(([api, { selected }]) => |
| 8986 | 8986 | new SlashCommandEnumValue(api, selected, enumTypes.getBasedOnIndex(uniqueAPIsUNIQUE_APIS.findIndex(x => x === selected)), |
| 8987 | 8987 | selected[0].toUpperCase() ?? enumIcons.default)), |
| 8988 | 8988 | }), |
| 8989 | 8989 | ], |
| @@ -1,7 +1,9 @@ | ||
| 1 | 1 | import { |
| 2 | 2 | Generate, |
| 3 | + UNIQUE_APIS, | |
| 3 | 4 | activateSendButtons, |
| 4 | 5 | addOneMessage, |
| 6 | + api_server, | |
| 5 | 7 | callPopup, |
| 6 | 8 | characters, |
| 7 | 9 | chat, |
| @@ -1496,7 +1498,8 @@ export function initDefaultSlashCommands() { | ||
| 1496 | 1498 | ], |
| 1497 | 1499 | helpString: 'Sets the specified prompt manager entry/entries on or off.', |
| 1498 | 1500 | })); |
| 1499 | 1501 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'pick-icon', |
| 1502 | + name: 'pick-icon', | |
| 1500 | 1503 | callback: async () => ((await showFontAwesomePicker()) ?? false).toString(), |
| 1501 | 1504 | returns: 'The chosen icon name or false if cancelled.', |
| 1502 | 1505 | helpString: ` |
| @@ -1522,8 +1525,9 @@ export function initDefaultSlashCommands() { | ||
| 1522 | 1525 | description: 'API to set/get the URL for - if not provided, current API is used', |
| 1523 | 1526 | typeList: [ARGUMENT_TYPE.STRING], |
| 1524 | 1527 | enumList: [ |
| 1525 | 1528 | new SlashCommandEnumValue('custom', 'custom openai OpenAI-compatible', enumTypes.getBasedOnIndex(uniqueAPIsUNIQUE_APIS.findIndex(x => x === 'openai')), 'O'), |
| 1526 | 1529 | ...Object.values(textgen_types).map(api => new SlashCommandEnumValue(api'kobold', null'KoboldAI Classic', enumTypes.getBasedOnIndex(uniqueAPIsUNIQUE_APIS.findIndex(x => x === 'textgenerationwebuikobold')), 'TK')), |
| 1530 | + ...Object.values(textgen_types).map(api => new SlashCommandEnumValue(api, null, enumTypes.getBasedOnIndex(UNIQUE_APIS.findIndex(x => x === 'textgenerationwebui')), 'T')), | |
| 1527 | 1531 | ], |
| 1528 | 1532 | }), |
| 1529 | 1533 | SlashCommandNamedArgument.fromProps({ |
| @@ -1549,7 +1553,7 @@ export function initDefaultSlashCommands() { | ||
| 1549 | 1553 | or consider switching to it with <code>/api</code> first. |
| 1550 | 1554 | </div> |
| 1551 | 1555 | <div> |
| 1552 | 1556 | This slash command works for most of the Text Completion sources, KoboldAI Classic, and also Custom OpenAI compatible for the Chat Completion sources. If unsure which APIs are supported, |
| 1553 | 1557 | check the auto-completion of the optional <code>api</code> argument of this command. |
| 1554 | 1558 | </div> |
| 1555 | 1559 | `, |
| @@ -3471,27 +3475,52 @@ function setPromptEntryCallback(args, targetState) { | ||
| 3471 | 3475 | * @returns {Promise<string>} |
| 3472 | 3476 | */ |
| 3473 | 3477 | async function setApiUrlCallback({ api = null, connect = 'true' }, url) { |
| 3478 | + const autoConnect = isTrueBoolean(connect); | |
| 3479 | + | |
| 3474 | 3480 | // Special handling for Chat Completion Custom OpenAI compatible, that one can also support API url handling |
| 3475 | 3481 | const isCurrentlyCustomOpenai = main_api === 'openai' && oai_settings.chat_completion_source === chat_completion_sources.CUSTOM; |
| 3476 | 3482 | if (api === chat_completion_sources.CUSTOM || (!api && isCurrentlyCustomOpenai)) { |
| 3477 | - if (url && !isCurrentlyCustomOpenai) { | |
| 3478 | - 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.'); | |
| 3479 | - return ''; | |
| 3480 | - } | |
| 3481 | - | |
| 3482 | 3483 | if (!url) { |
| 3483 | 3484 | return oai_settings.custom_url ?? ''; |
| 3484 | 3485 | } |
| 3485 | 3486 | |
| 3487 | + if (!isCurrentlyCustomOpenai && autoConnect) { | |
| 3488 | + 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.'); | |
| 3489 | + return ''; | |
| 3490 | + } | |
| 3491 | + | |
| 3486 | 3492 | $('#custom_api_url_text').val(url).trigger('input'); |
| 3487 | 3493 | |
| 3488 | 3494 | if (isTrueBoolean(connect)autoConnect) { |
| 3489 | 3495 | $('#api_button_openai').trigger('click'); |
| 3490 | 3496 | } |
| 3491 | 3497 | |
| 3492 | 3498 | return url; |
| 3493 | 3499 | } |
| 3494 | 3500 | |
| 3501 | + // Special handling for Kobold Classic API | |
| 3502 | + const isCurrentlyKoboldClassic = main_api === 'kobold'; | |
| 3503 | + if (api === 'kobold' || (!api && isCurrentlyKoboldClassic)) { | |
| 3504 | + if (!url) { | |
| 3505 | + return api_server ?? ''; | |
| 3506 | + } | |
| 3507 | + | |
| 3508 | + if (!isCurrentlyKoboldClassic && autoConnect) { | |
| 3509 | + toastr.warning('Kobold Classic API is not the currently selected API, so we cannot do an auto-connect. Consider switching to it via /api beforehand.'); | |
| 3510 | + return ''; | |
| 3511 | + } | |
| 3512 | + | |
| 3513 | + $('#api_url_text').val(url).trigger('input'); | |
| 3514 | + // trigger blur debounced, so we hide the autocomplete menu | |
| 3515 | + setTimeout(() => $('#api_url_text').trigger('blur'), 1); | |
| 3516 | + | |
| 3517 | + if (autoConnect) { | |
| 3518 | + $('#api_button').trigger('click'); | |
| 3519 | + } | |
| 3520 | + | |
| 3521 | + return api_server ?? ''; | |
| 3522 | + } | |
| 3523 | + | |
| 3495 | 3524 | // Do some checks and get the api type we are targeting with this command |
| 3496 | 3525 | if (api && !Object.values(textgen_types).includes(api)) { |
| 3497 | 3526 | toastr.warning(`API '${api}' is not a valid text_gen API.`); |
| @@ -3501,7 +3530,7 @@ async function setApiUrlCallback({ api = null, connect = 'true' }, url) { | ||
| 3501 | 3530 | toastr.warning(`API '${textgenerationwebui_settings.type}' is not a valid text_gen API.`); |
| 3502 | 3531 | return ''; |
| 3503 | 3532 | } |
| 3504 | 3533 | if (api && url && isTrueBoolean(connect)autoConnect && api !== textgenerationwebui_settings.type) { |
| 3505 | 3534 | toastr.warning(`API '${api}' is not the currently selected API, so we cannot do an auto-connect. Consider switching to it via /api beforehand.`); |
| 3506 | 3535 | return ''; |
| 3507 | 3536 | } |
| @@ -3524,7 +3553,7 @@ async function setApiUrlCallback({ api = null, connect = 'true' }, url) { | ||
| 3524 | 3553 | setTimeout(() => $(inputSelector).trigger('blur'), 1); |
| 3525 | 3554 | |
| 3526 | 3555 | // Trigger the auto connect via connect button, if requested |
| 3527 | 3556 | if (isTrueBoolean(connect)autoConnect) { |
| 3528 | 3557 | $('#api_button_textgenerationwebui').trigger('click'); |
| 3529 | 3558 | } |
| 3530 | 3559 | |