diff --git a/public/script.js b/public/script.js index 10cc3ad6a..88897114a 100644 --- a/public/script.js +++ b/public/script.js @@ -1068,10 +1068,10 @@ function messageFormatting(mes, ch_name, isSystem, isUser) { mes = converter.makeHtml(mes); mes = mes.replace(/{{(\*?.*\*?)}}/g, ""); - mes = mes.replace(/[\s\S]*?<\/code>/g, function (match) { - // Firefox creates extra newlines from
s in code blocks, so we replace them before converting newlines to
s. - return match.replace(/\n/gm, '\u0000'); - }) + mes = mes.replace(/[\s\S]*?<\/code>/g, function (match) { + // Firefox creates extra newlines from
s in code blocks, so we replace them before converting newlines to
s. + return match.replace(/\n/gm, '\u0000'); + }) mes = mes.replace(/\n/g, "
"); mes = mes.replace(/\u0000/g, "\n"); // Restore converted newlines mes = mes.trim(); @@ -5955,6 +5955,64 @@ function displayOverrideWarnings() { $('.jailbreak_overridden').toggle(!!(characters[this_chid]?.data?.post_history_instructions)); } +function connectAPISlash(_, text) { + if (!text) return; + + const apiMap = { + 'kobold': { + button: '#api_button', + }, + 'horde': { + selected: 'koboldhorde', + }, + 'novel': { + button: '#api_button_novel', + }, + 'ooba': { + button: '#api_button_textgenerationwebui', + }, + 'oai': { + selected: 'openai', + source: 'openai', + button: '#api_button_openai', + }, + 'claude': { + selected: 'openai', + source: 'claude', + button: '#api_button_openai', + }, + 'windowai': { + selected: 'openai', + source: 'windowai', + button: '#api_button_openai', + }, + 'poe': { + button: '#poe_connect', + }, + }; + + const apiConfig = apiMap[text]; + if (!apiConfig) { + toastr.error(`Error: ${text} is not a valid API`); + return; + } + + $("#main_api option[value='" + (apiConfig.selected || text) + "']").prop("selected", true); + $("#main_api").trigger('change'); + + if (apiConfig.source) { + $("#chat_completion_source option[value='" + apiConfig.source + "']").prop("selected", true); + $("#chat_completion_source").trigger('change'); + } + + if (apiConfig.button) { + $(apiConfig.button).trigger('click'); + } + + toastr.info(`API set to ${text}, trying to connect..`); +} + + // Check for override warnings every 5 seconds... setInterval(displayOverrideWarnings, 5000); // ...or when the chat changes @@ -6017,6 +6075,7 @@ $(document).ready(function () { //////////INPUT BAR FOCUS-KEEPING LOGIC///////////// registerSlashCommand('dupe', DupeChar, [], "– duplicates the currently selected character", true, true); + registerSlashCommand('api', connectAPISlash, [], "– connect to an API", true, true); setTimeout(function () { $("#groupControlsToggle").trigger('click'); diff --git a/public/scripts/extensions/quick-reply/index.js b/public/scripts/extensions/quick-reply/index.js index 2dbced4eb..437732e21 100644 --- a/public/scripts/extensions/quick-reply/index.js +++ b/public/scripts/extensions/quick-reply/index.js @@ -91,7 +91,7 @@ function addQuickReplyBar(numButtons) { $('#send_form').prepend(quickReplyBarFullHtml); $('.quickReplyButton').on('click', function () { - console.log('got quick reply click'); + //console.log('got quick reply click'); let quickReplyButtonID = $(this).attr('id'); sendQuickReply(quickReplyButtonID); });