Add support for Kobold Classic
This commit is contained in:
parent
7b3d13ac00
commit
abdf1f29cf
|
@ -8392,6 +8392,9 @@ const CONNECT_API_MAP = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Collect all unique API names in an array
|
||||||
|
export const UNIQUE_APIS = [...new Set(Object.values(CONNECT_API_MAP).map(x => x.selected))];
|
||||||
|
|
||||||
// Fill connections map from textgen_types and chat_completion_sources
|
// Fill connections map from textgen_types and chat_completion_sources
|
||||||
for (const textGenType of Object.values(textgen_types)) {
|
for (const textGenType of Object.values(textgen_types)) {
|
||||||
if (CONNECT_API_MAP[textGenType]) continue;
|
if (CONNECT_API_MAP[textGenType]) continue;
|
||||||
|
@ -8966,9 +8969,6 @@ jQuery(async function () {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect all unique API names in an array
|
|
||||||
const uniqueAPIs = [...new Set(Object.values(CONNECT_API_MAP).map(x => x.selected))];
|
|
||||||
|
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
name: 'dupe',
|
name: 'dupe',
|
||||||
callback: duplicateCharacter,
|
callback: duplicateCharacter,
|
||||||
|
@ -8983,7 +8983,7 @@ jQuery(async function () {
|
||||||
description: 'API to connect to',
|
description: 'API to connect to',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
enumList: Object.entries(CONNECT_API_MAP).map(([api, { selected }]) =>
|
enumList: Object.entries(CONNECT_API_MAP).map(([api, { selected }]) =>
|
||||||
new SlashCommandEnumValue(api, selected, enumTypes.getBasedOnIndex(uniqueAPIs.findIndex(x => x === selected)),
|
new SlashCommandEnumValue(api, selected, enumTypes.getBasedOnIndex(UNIQUE_APIS.findIndex(x => x === selected)),
|
||||||
selected[0].toUpperCase() ?? enumIcons.default)),
|
selected[0].toUpperCase() ?? enumIcons.default)),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import {
|
import {
|
||||||
Generate,
|
Generate,
|
||||||
|
UNIQUE_APIS,
|
||||||
activateSendButtons,
|
activateSendButtons,
|
||||||
addOneMessage,
|
addOneMessage,
|
||||||
|
api_server,
|
||||||
callPopup,
|
callPopup,
|
||||||
characters,
|
characters,
|
||||||
chat,
|
chat,
|
||||||
|
@ -1496,7 +1498,8 @@ export function initDefaultSlashCommands() {
|
||||||
],
|
],
|
||||||
helpString: 'Sets the specified prompt manager entry/entries on or off.',
|
helpString: 'Sets the specified prompt manager entry/entries on or off.',
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'pick-icon',
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
|
name: 'pick-icon',
|
||||||
callback: async () => ((await showFontAwesomePicker()) ?? false).toString(),
|
callback: async () => ((await showFontAwesomePicker()) ?? false).toString(),
|
||||||
returns: 'The chosen icon name or false if cancelled.',
|
returns: 'The chosen icon name or false if cancelled.',
|
||||||
helpString: `
|
helpString: `
|
||||||
|
@ -1522,8 +1525,9 @@ export function initDefaultSlashCommands() {
|
||||||
description: 'API to set/get the URL for - if not provided, current API is used',
|
description: 'API to set/get the URL for - if not provided, current API is used',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
enumList: [
|
enumList: [
|
||||||
new SlashCommandEnumValue('custom', 'custom openai compatible', enumTypes.getBasedOnIndex(uniqueAPIs.findIndex(x => x === 'openai')), 'O'),
|
new SlashCommandEnumValue('custom', 'custom OpenAI-compatible', enumTypes.getBasedOnIndex(UNIQUE_APIS.findIndex(x => x === 'openai')), 'O'),
|
||||||
...Object.values(textgen_types).map(api => new SlashCommandEnumValue(api, null, enumTypes.getBasedOnIndex(uniqueAPIs.findIndex(x => x === 'textgenerationwebui')), 'T')),
|
new SlashCommandEnumValue('kobold', 'KoboldAI Classic', enumTypes.getBasedOnIndex(UNIQUE_APIS.findIndex(x => x === 'kobold')), 'K'),
|
||||||
|
...Object.values(textgen_types).map(api => new SlashCommandEnumValue(api, null, enumTypes.getBasedOnIndex(UNIQUE_APIS.findIndex(x => x === 'textgenerationwebui')), 'T')),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
SlashCommandNamedArgument.fromProps({
|
SlashCommandNamedArgument.fromProps({
|
||||||
|
@ -1549,7 +1553,7 @@ export function initDefaultSlashCommands() {
|
||||||
or consider switching to it with <code>/api</code> first.
|
or consider switching to it with <code>/api</code> first.
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
This slash command works for most of the Text Completion sources, and also Custom OpenAI compatible for the Chat Completion sources. If unsure which APIs are supported,
|
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,
|
||||||
check the auto-completion of the optional <code>api</code> argument of this command.
|
check the auto-completion of the optional <code>api</code> argument of this command.
|
||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
|
@ -3471,27 +3475,52 @@ function setPromptEntryCallback(args, targetState) {
|
||||||
* @returns {Promise<string>}
|
* @returns {Promise<string>}
|
||||||
*/
|
*/
|
||||||
async function setApiUrlCallback({ api = null, connect = 'true' }, url) {
|
async function setApiUrlCallback({ api = null, connect = 'true' }, url) {
|
||||||
|
const autoConnect = isTrueBoolean(connect);
|
||||||
|
|
||||||
// Special handling for Chat Completion Custom OpenAI compatible, that one can also support API url handling
|
// Special handling for Chat Completion Custom OpenAI compatible, that one can also support API url handling
|
||||||
const isCurrentlyCustomOpenai = main_api === 'openai' && oai_settings.chat_completion_source === chat_completion_sources.CUSTOM;
|
const isCurrentlyCustomOpenai = main_api === 'openai' && oai_settings.chat_completion_source === chat_completion_sources.CUSTOM;
|
||||||
if (api === chat_completion_sources.CUSTOM || (!api && isCurrentlyCustomOpenai)) {
|
if (api === chat_completion_sources.CUSTOM || (!api && isCurrentlyCustomOpenai)) {
|
||||||
if (url && !isCurrentlyCustomOpenai) {
|
|
||||||
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.');
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return oai_settings.custom_url ?? '';
|
return oai_settings.custom_url ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isCurrentlyCustomOpenai && autoConnect) {
|
||||||
|
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.');
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
$('#custom_api_url_text').val(url).trigger('input');
|
$('#custom_api_url_text').val(url).trigger('input');
|
||||||
|
|
||||||
if (isTrueBoolean(connect)) {
|
if (autoConnect) {
|
||||||
$('#api_button_openai').trigger('click');
|
$('#api_button_openai').trigger('click');
|
||||||
}
|
}
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Special handling for Kobold Classic API
|
||||||
|
const isCurrentlyKoboldClassic = main_api === 'kobold';
|
||||||
|
if (api === 'kobold' || (!api && isCurrentlyKoboldClassic)) {
|
||||||
|
if (!url) {
|
||||||
|
return api_server ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isCurrentlyKoboldClassic && autoConnect) {
|
||||||
|
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.');
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#api_url_text').val(url).trigger('input');
|
||||||
|
// trigger blur debounced, so we hide the autocomplete menu
|
||||||
|
setTimeout(() => $('#api_url_text').trigger('blur'), 1);
|
||||||
|
|
||||||
|
if (autoConnect) {
|
||||||
|
$('#api_button').trigger('click');
|
||||||
|
}
|
||||||
|
|
||||||
|
return api_server ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
// Do some checks and get the api type we are targeting with this command
|
// Do some checks and get the api type we are targeting with this command
|
||||||
if (api && !Object.values(textgen_types).includes(api)) {
|
if (api && !Object.values(textgen_types).includes(api)) {
|
||||||
toastr.warning(`API '${api}' is not a valid text_gen API.`);
|
toastr.warning(`API '${api}' is not a valid text_gen API.`);
|
||||||
|
@ -3501,7 +3530,7 @@ async function setApiUrlCallback({ api = null, connect = 'true' }, url) {
|
||||||
toastr.warning(`API '${textgenerationwebui_settings.type}' is not a valid text_gen API.`);
|
toastr.warning(`API '${textgenerationwebui_settings.type}' is not a valid text_gen API.`);
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
if (api && url && isTrueBoolean(connect) && api !== textgenerationwebui_settings.type) {
|
if (api && url && autoConnect && api !== textgenerationwebui_settings.type) {
|
||||||
toastr.warning(`API '${api}' is not the currently selected API, so we cannot do an auto-connect. Consider switching to it via /api beforehand.`);
|
toastr.warning(`API '${api}' is not the currently selected API, so we cannot do an auto-connect. Consider switching to it via /api beforehand.`);
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -3524,7 +3553,7 @@ async function setApiUrlCallback({ api = null, connect = 'true' }, url) {
|
||||||
setTimeout(() => $(inputSelector).trigger('blur'), 1);
|
setTimeout(() => $(inputSelector).trigger('blur'), 1);
|
||||||
|
|
||||||
// Trigger the auto connect via connect button, if requested
|
// Trigger the auto connect via connect button, if requested
|
||||||
if (isTrueBoolean(connect)) {
|
if (autoConnect) {
|
||||||
$('#api_button_textgenerationwebui').trigger('click');
|
$('#api_button_textgenerationwebui').trigger('click');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue