From 003066a036f8640d875b44230b32b585e82445fc Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 29 Jun 2024 00:33:12 +0300 Subject: [PATCH 1/8] Add vLLM as multimodal captioning source --- public/scripts/extensions/caption/index.js | 1 + public/scripts/extensions/caption/settings.html | 2 ++ public/scripts/extensions/shared.js | 17 +++++++++++++++++ src/endpoints/openai.js | 8 ++++++-- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/public/scripts/extensions/caption/index.js b/public/scripts/extensions/caption/index.js index e06449f88..543eef7f6 100644 --- a/public/scripts/extensions/caption/index.js +++ b/public/scripts/extensions/caption/index.js @@ -356,6 +356,7 @@ jQuery(async function () { (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'llamacpp' && textgenerationwebui_settings.server_urls[textgen_types.LLAMACPP]) || (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'ooba' && textgenerationwebui_settings.server_urls[textgen_types.OOBA]) || (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'koboldcpp' && textgenerationwebui_settings.server_urls[textgen_types.KOBOLDCPP]) || + (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'vllm' && textgenerationwebui_settings.server_urls[textgen_types.VLLM]) || (extension_settings.caption.source === 'multimodal' && extension_settings.caption.multimodal_api === 'custom') || extension_settings.caption.source === 'local' || extension_settings.caption.source === 'horde'; diff --git a/public/scripts/extensions/caption/settings.html b/public/scripts/extensions/caption/settings.html index 3e23cfbd5..90ff673ba 100644 --- a/public/scripts/extensions/caption/settings.html +++ b/public/scripts/extensions/caption/settings.html @@ -26,6 +26,7 @@ +
@@ -66,6 +67,7 @@ +
diff --git a/public/scripts/extensions/shared.js b/public/scripts/extensions/shared.js index 4a4390318..3e671c3af 100644 --- a/public/scripts/extensions/shared.js +++ b/public/scripts/extensions/shared.js @@ -34,6 +34,7 @@ export async function getMultimodalCaption(base64Img, prompt) { const isCustom = extension_settings.caption.multimodal_api === 'custom'; const isOoba = extension_settings.caption.multimodal_api === 'ooba'; const isKoboldCpp = extension_settings.caption.multimodal_api === 'koboldcpp'; + const isVllm = extension_settings.caption.multimodal_api === 'vllm'; const base64Bytes = base64Img.length * 0.75; const compressionLimit = 2 * 1024 * 1024; if ((['google', 'openrouter'].includes(extension_settings.caption.multimodal_api) && base64Bytes > compressionLimit) || isOoba || isKoboldCpp) { @@ -65,6 +66,14 @@ export async function getMultimodalCaption(base64Img, prompt) { requestBody.server_url = textgenerationwebui_settings.server_urls[textgen_types.OLLAMA]; } + if (isVllm) { + if (extension_settings.caption.multimodal_model === 'vllm_current') { + requestBody.model = textgenerationwebui_settings.vllm_model; + } + + requestBody.server_url = textgenerationwebui_settings.server_urls[textgen_types.VLLM]; + } + if (isLlamaCpp) { requestBody.server_url = textgenerationwebui_settings.server_urls[textgen_types.LLAMACPP]; } @@ -151,6 +160,14 @@ function throwIfInvalidModel(useReverseProxy) { throw new Error('KoboldCpp server URL is not set.'); } + if (extension_settings.caption.multimodal_api === 'vllm' && !textgenerationwebui_settings.server_urls[textgen_types.VLLM]) { + throw new Error('vLLM server URL is not set.'); + } + + if (extension_settings.caption.multimodal_api === 'vllm' && extension_settings.caption.multimodal_model === 'vllm_current' && !textgenerationwebui_settings.vllm_model) { + throw new Error('vLLM model is not set.'); + } + if (extension_settings.caption.multimodal_api === 'custom' && !oai_settings.custom_url) { throw new Error('Custom API URL is not set.'); } diff --git a/src/endpoints/openai.js b/src/endpoints/openai.js index 75de75b7b..f63d72b11 100644 --- a/src/endpoints/openai.js +++ b/src/endpoints/openai.js @@ -43,7 +43,11 @@ router.post('/caption-image', jsonParser, async (request, response) => { key = readSecret(request.user.directories, SECRET_KEYS.KOBOLDCPP); } - if (!key && !request.body.reverse_proxy && ['custom', 'ooba', 'koboldcpp'].includes(request.body.api) === false) { + if (request.body.api === 'vllm') { + key = readSecret(request.user.directories, SECRET_KEYS.VLLM); + } + + if (!key && !request.body.reverse_proxy && ['custom', 'ooba', 'koboldcpp', 'vllm'].includes(request.body.api) === false) { console.log('No key found for API', request.body.api); return response.sendStatus(400); } @@ -110,7 +114,7 @@ router.post('/caption-image', jsonParser, async (request, response) => { }); } - if (request.body.api === 'koboldcpp') { + if (request.body.api === 'koboldcpp' || request.body.api === 'vllm') { apiUrl = `${trimV1(request.body.server_url)}/v1/chat/completions`; } From cba2b54531293167424a7f4f17f3ba979cbe9a0a Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sat, 29 Jun 2024 00:25:10 +0200 Subject: [PATCH 2/8] Refactor main slassh-commands into init func --- public/script.js | 3 +- public/scripts/slash-commands.js | 1931 +++++++++++++++--------------- 2 files changed, 968 insertions(+), 966 deletions(-) diff --git a/public/script.js b/public/script.js index 8c9f10c6c..4534e12d6 100644 --- a/public/script.js +++ b/public/script.js @@ -159,7 +159,7 @@ import { import { debounce_timeout } from './scripts/constants.js'; import { ModuleWorkerWrapper, doDailyExtensionUpdatesCheck, extension_settings, getContext, loadExtensionSettings, renderExtensionTemplate, renderExtensionTemplateAsync, runGenerationInterceptors, saveMetadataDebounced, writeExtensionField } from './scripts/extensions.js'; -import { COMMENT_NAME_DEFAULT, executeSlashCommands, executeSlashCommandsOnChatInput, getSlashCommandsHelp, isExecutingCommandsFromChatInput, pauseScriptExecution, processChatSlashCommands, registerSlashCommand, stopScriptExecution } from './scripts/slash-commands.js'; +import { COMMENT_NAME_DEFAULT, executeSlashCommands, executeSlashCommandsOnChatInput, getSlashCommandsHelp, initDefaultSlashCommands, isExecutingCommandsFromChatInput, pauseScriptExecution, processChatSlashCommands, registerSlashCommand, stopScriptExecution } from './scripts/slash-commands.js'; import { tag_map, tags, @@ -911,6 +911,7 @@ async function firstLoadInit() { initKeyboard(); initDynamicStyles(); initTags(); + initDefaultSlashCommands(); await getUserAvatars(true, user_avatar); await getCharacters(); await getBackgrounds(); diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index c595175d2..3573453bd 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -38,13 +38,13 @@ import { system_message_types, this_chid, } from '../script.js'; -import { PARSER_FLAG, SlashCommandParser } from './slash-commands/SlashCommandParser.js'; +import { SlashCommandParser } from './slash-commands/SlashCommandParser.js'; import { SlashCommandParserError } from './slash-commands/SlashCommandParserError.js'; import { getMessageTimeStamp } from './RossAscends-mods.js'; import { hideChatMessageRange } from './chats.js'; -import { extension_settings, getContext, saveMetadataDebounced } from './extensions.js'; +import { getContext, saveMetadataDebounced } from './extensions.js'; import { getRegexedString, regex_placement } from './extensions/regex/engine.js'; -import { findGroupMemberId, getGroupMembers, groups, is_group_generating, openGroupById, resetSelectedGroup, saveGroupChat, selected_group } from './group-chats.js'; +import { findGroupMemberId, groups, is_group_generating, openGroupById, resetSelectedGroup, saveGroupChat, selected_group } from './group-chats.js'; import { chat_completion_sources, oai_settings, setupChatCompletionPromptManager } from './openai.js'; import { autoSelectPersona, retriggerFirstMessageOnEmptyChat, setPersonaLockState, togglePersonaLock, user_avatar } from './personas.js'; import { addEphemeralStoppingString, chat_styles, flushEphemeralStoppingStrings, power_user } from './power-user.js'; @@ -53,7 +53,6 @@ import { decodeTextTokens, getFriendlyTokenizerName, getTextTokens, getTokenCoun import { debounce, delay, isFalseBoolean, isTrueBoolean, stringToRange, trimToEndSentence, trimToStartSentence, waitUntilCondition } from './utils.js'; import { registerVariableCommands, resolveVariable } from './variables.js'; import { background_settings } from './backgrounds.js'; -import { SlashCommandScope } from './slash-commands/SlashCommandScope.js'; import { SlashCommandClosure } from './slash-commands/SlashCommandClosure.js'; import { SlashCommandClosureResult } from './slash-commands/SlashCommandClosureResult.js'; import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js'; @@ -75,78 +74,79 @@ export const parser = new SlashCommandParser(); const registerSlashCommand = SlashCommandParser.addCommand.bind(SlashCommandParser); const getSlashCommandsHelp = parser.getHelpString.bind(parser); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: '?', - callback: helpCommandCallback, - aliases: ['help'], - unnamedArgumentList: [SlashCommandArgument.fromProps({ - description: 'help topic', - typeList: [ARGUMENT_TYPE.STRING], - enumList: [ - new SlashCommandEnumValue('slash', 'slash commands (STscript)', enumTypes.command, '/'), - new SlashCommandEnumValue('macros', '{{macros}} (text replacement)', enumTypes.macro, enumIcons.macro), - new SlashCommandEnumValue('format', 'chat/text formatting', enumTypes.name, '★'), - new SlashCommandEnumValue('hotkeys', 'keyboard shortcuts', enumTypes.enum, '⏎'), +export function initDefaultSlashCommands() { + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: '?', + callback: helpCommandCallback, + aliases: ['help'], + unnamedArgumentList: [SlashCommandArgument.fromProps({ + description: 'help topic', + typeList: [ARGUMENT_TYPE.STRING], + enumList: [ + new SlashCommandEnumValue('slash', 'slash commands (STscript)', enumTypes.command, '/'), + new SlashCommandEnumValue('macros', '{{macros}} (text replacement)', enumTypes.macro, enumIcons.macro), + new SlashCommandEnumValue('format', 'chat/text formatting', enumTypes.name, '★'), + new SlashCommandEnumValue('hotkeys', 'keyboard shortcuts', enumTypes.enum, '⏎'), + ], + })], + helpString: 'Get help on macros, chat formatting and commands.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'persona', + callback: setNameCallback, + namedArgumentList: [ + new SlashCommandNamedArgument( + 'mode', 'The mode for persona selection. ("lookup" = search for existing persona, "temp" = create a temporary name, set a temporary name, "all" = allow both in the same command)', + [ARGUMENT_TYPE.STRING], false, false, 'all', ['lookup', 'temp', 'all'], + ), ], - })], - helpString: 'Get help on macros, chat formatting and commands.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'persona', - callback: setNameCallback, - namedArgumentList: [ - new SlashCommandNamedArgument( - 'mode', 'The mode for persona selection. ("lookup" = search for existing persona, "temp" = create a temporary name, set a temporary name, "all" = allow both in the same command)', - [ARGUMENT_TYPE.STRING], false, false, 'all', ['lookup', 'temp', 'all'], - ), - ], - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'persona name', - typeList: [ARGUMENT_TYPE.STRING], - isRequired: true, - enumProvider: commonEnumProviders.personas, - }), - ], - helpString: 'Selects the given persona with its name and avatar (by name or avatar url). If no matching persona exists, applies a temporary name.', - aliases: ['name'], -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'sync', - callback: syncCallback, - helpString: 'Syncs the user persona in user-attributed messages in the current chat.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'lock', - callback: lockPersonaCallback, - aliases: ['bind'], - helpString: 'Locks/unlocks a persona (name and avatar) to the current chat', - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'state', - typeList: [ARGUMENT_TYPE.STRING], - isRequired: true, - defaultValue: 'toggle', - enumProvider: commonEnumProviders.boolean('onOffToggle'), - }), - ], -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'bg', - callback: setBackgroundCallback, - aliases: ['background'], - returns: 'the current background', - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'filename', - typeList: [ARGUMENT_TYPE.STRING], - isRequired: true, - enumProvider: () => [...document.querySelectorAll('.bg_example')] - .map(it => new SlashCommandEnumValue(it.getAttribute('bgfile'))) - .filter(it => it.value?.length), - }), - ], - helpString: ` + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'persona name', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: true, + enumProvider: commonEnumProviders.personas, + }), + ], + helpString: 'Selects the given persona with its name and avatar (by name or avatar url). If no matching persona exists, applies a temporary name.', + aliases: ['name'], + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'sync', + callback: syncCallback, + helpString: 'Syncs the user persona in user-attributed messages in the current chat.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'lock', + callback: lockPersonaCallback, + aliases: ['bind'], + helpString: 'Locks/unlocks a persona (name and avatar) to the current chat', + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'state', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: true, + defaultValue: 'toggle', + enumProvider: commonEnumProviders.boolean('onOffToggle'), + }), + ], + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'bg', + callback: setBackgroundCallback, + aliases: ['background'], + returns: 'the current background', + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'filename', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: true, + enumProvider: () => [...document.querySelectorAll('.bg_example')] + .map(it => new SlashCommandEnumValue(it.getAttribute('bgfile'))) + .filter(it => it.value?.length), + }), + ], + helpString: `
Sets a background according to the provided filename. Partial names allowed.
@@ -159,35 +159,35 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'sendas', - callback: sendMessageAs, - namedArgumentList: [ - SlashCommandNamedArgument.fromProps({ - name: 'name', - description: 'Character name', - typeList: [ARGUMENT_TYPE.STRING], - isRequired: true, - enumProvider: commonEnumProviders.characters('character'), - forceEnum: false, - }), - new SlashCommandNamedArgument( - 'compact', 'Use compact layout', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false', - ), - SlashCommandNamedArgument.fromProps({ - name: 'at', - description: 'position to insert the message', - typeList: [ARGUMENT_TYPE.NUMBER], - enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), - }), - ], - unnamedArgumentList: [ - new SlashCommandArgument( - 'text', [ARGUMENT_TYPE.STRING], true, - ), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'sendas', + callback: sendMessageAs, + namedArgumentList: [ + SlashCommandNamedArgument.fromProps({ + name: 'name', + description: 'Character name', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: true, + enumProvider: commonEnumProviders.characters('character'), + forceEnum: false, + }), + new SlashCommandNamedArgument( + 'compact', 'Use compact layout', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false', + ), + SlashCommandNamedArgument.fromProps({ + name: 'at', + description: 'position to insert the message', + typeList: [ARGUMENT_TYPE.NUMBER], + enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), + }), + ], + unnamedArgumentList: [ + new SlashCommandArgument( + 'text', [ARGUMENT_TYPE.STRING], true, + ), + ], + helpString: `
Sends a message as a specific character. Uses the character avatar if it exists in the characters list.
@@ -204,33 +204,33 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ If "compact" is set to true, the message is sent using a compact layout. `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'sys', - callback: sendNarratorMessage, - aliases: ['nar'], - namedArgumentList: [ - new SlashCommandNamedArgument( - 'compact', - 'compact layout', - [ARGUMENT_TYPE.BOOLEAN], - false, - false, - 'false', - ), - SlashCommandNamedArgument.fromProps({ - name: 'at', - description: 'position to insert the message', - typeList: [ARGUMENT_TYPE.NUMBER], - enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), - }), - ], - unnamedArgumentList: [ - new SlashCommandArgument( - 'text', [ARGUMENT_TYPE.STRING], true, - ), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'sys', + callback: sendNarratorMessage, + aliases: ['nar'], + namedArgumentList: [ + new SlashCommandNamedArgument( + 'compact', + 'compact layout', + [ARGUMENT_TYPE.BOOLEAN], + false, + false, + 'false', + ), + SlashCommandNamedArgument.fromProps({ + name: 'at', + description: 'position to insert the message', + typeList: [ARGUMENT_TYPE.NUMBER], + enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), + }), + ], + unnamedArgumentList: [ + new SlashCommandArgument( + 'text', [ARGUMENT_TYPE.STRING], true, + ), + ], + helpString: `
Sends a message as a system narrator.
@@ -249,44 +249,44 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'sysname', - callback: setNarratorName, - unnamedArgumentList: [ - new SlashCommandArgument( - 'name', [ARGUMENT_TYPE.STRING], false, - ), - ], - helpString: 'Sets a name for future system narrator messages in this chat (display only). Default: System. Leave empty to reset.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'comment', - callback: sendCommentMessage, - namedArgumentList: [ - new SlashCommandNamedArgument( - 'compact', - 'Whether to use a compact layout', - [ARGUMENT_TYPE.BOOLEAN], - false, - false, - 'false', - ), - SlashCommandNamedArgument.fromProps({ - name: 'at', - description: 'position to insert the message', - typeList: [ARGUMENT_TYPE.NUMBER], - enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), - }), - ], - unnamedArgumentList: [ - new SlashCommandArgument( - 'text', - [ARGUMENT_TYPE.STRING], - true, - ), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'sysname', + callback: setNarratorName, + unnamedArgumentList: [ + new SlashCommandArgument( + 'name', [ARGUMENT_TYPE.STRING], false, + ), + ], + helpString: 'Sets a name for future system narrator messages in this chat (display only). Default: System. Leave empty to reset.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'comment', + callback: sendCommentMessage, + namedArgumentList: [ + new SlashCommandNamedArgument( + 'compact', + 'Whether to use a compact layout', + [ARGUMENT_TYPE.BOOLEAN], + false, + false, + 'false', + ), + SlashCommandNamedArgument.fromProps({ + name: 'at', + description: 'position to insert the message', + typeList: [ARGUMENT_TYPE.NUMBER], + enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), + }), + ], + unnamedArgumentList: [ + new SlashCommandArgument( + 'text', + [ARGUMENT_TYPE.STRING], + true, + ), + ], + helpString: `
Adds a note/comment message not part of the chat.
@@ -305,35 +305,35 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'single', - callback: setStoryModeCallback, - aliases: ['story'], - helpString: 'Sets the message style to single document mode without names or avatars visible.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'bubble', - callback: setBubbleModeCallback, - aliases: ['bubbles'], - helpString: 'Sets the message style to bubble chat mode.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'flat', - callback: setFlatModeCallback, - aliases: ['default'], - helpString: 'Sets the message style to flat chat mode.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'continue', - callback: continueChatCallback, - aliases: ['cont'], - unnamedArgumentList: [ - new SlashCommandArgument( - 'prompt', [ARGUMENT_TYPE.STRING], false, - ), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'single', + callback: setStoryModeCallback, + aliases: ['story'], + helpString: 'Sets the message style to single document mode without names or avatars visible.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'bubble', + callback: setBubbleModeCallback, + aliases: ['bubbles'], + helpString: 'Sets the message style to bubble chat mode.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'flat', + callback: setFlatModeCallback, + aliases: ['default'], + helpString: 'Sets the message style to flat chat mode.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'continue', + callback: continueChatCallback, + aliases: ['cont'], + unnamedArgumentList: [ + new SlashCommandArgument( + 'prompt', [ARGUMENT_TYPE.STRING], false, + ), + ], + helpString: `
Continues the last message in the chat, with an optional additional prompt.
@@ -351,87 +351,87 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'go', - callback: goToCharacterCallback, - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'name', - typeList: [ARGUMENT_TYPE.STRING], - isRequired: true, - enumProvider: commonEnumProviders.characters('all'), - }), - ], - helpString: 'Opens up a chat with the character or group by its name', - aliases: ['char'], -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'rename-char', - /** @param {{silent: string, chats: string}} options @param {string} name */ - callback: async ({ silent = 'true', chats = null }, name) => { - const renamed = await renameCharacter(name, { silent: isTrueBoolean(silent), renameChats: chats !== null ? isTrueBoolean(chats) : null }); - return String(renamed); - }, - returns: 'true/false - Whether the rename was successful', - namedArgumentList: [ - new SlashCommandNamedArgument( - 'silent', 'Hide any blocking popups. (if false, the name is optional. If not supplied, a popup asking for it will appear)', [ARGUMENT_TYPE.BOOLEAN], false, false, 'true', - ), - new SlashCommandNamedArgument( - 'chats', 'Rename char in all previous chats', [ARGUMENT_TYPE.BOOLEAN], false, false, '', - ), - ], - unnamedArgumentList: [ - new SlashCommandArgument( - 'new char name', [ARGUMENT_TYPE.STRING], true, - ), - ], - helpString: 'Renames the current character.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'sysgen', - callback: generateSystemMessage, - unnamedArgumentList: [ - new SlashCommandArgument( - 'prompt', [ARGUMENT_TYPE.STRING], true, - ), - ], - helpString: 'Generates a system message using a specified prompt.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'ask', - callback: askCharacter, - namedArgumentList: [ - SlashCommandNamedArgument.fromProps({ - name: 'name', - description: 'character name', - typeList: [ARGUMENT_TYPE.STRING], - isRequired: true, - enumProvider: commonEnumProviders.characters('character'), - }), - ], - unnamedArgumentList: [ - new SlashCommandArgument( - 'prompt', [ARGUMENT_TYPE.STRING], true, false, - ), - ], - helpString: 'Asks a specified character card a prompt. Character name must be provided in a named argument.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'delname', - callback: deleteMessagesByNameCallback, - namedArgumentList: [], - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'name', - typeList: [ARGUMENT_TYPE.STRING], - isRequired: true, - enumProvider: commonEnumProviders.characters('character'), - }), - ], - aliases: ['cancel'], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'go', + callback: goToCharacterCallback, + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'name', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: true, + enumProvider: commonEnumProviders.characters('all'), + }), + ], + helpString: 'Opens up a chat with the character or group by its name', + aliases: ['char'], + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'rename-char', + /** @param {{silent: string, chats: string}} options @param {string} name */ + callback: async ({ silent = 'true', chats = null }, name) => { + const renamed = await renameCharacter(name, { silent: isTrueBoolean(silent), renameChats: chats !== null ? isTrueBoolean(chats) : null }); + return String(renamed); + }, + returns: 'true/false - Whether the rename was successful', + namedArgumentList: [ + new SlashCommandNamedArgument( + 'silent', 'Hide any blocking popups. (if false, the name is optional. If not supplied, a popup asking for it will appear)', [ARGUMENT_TYPE.BOOLEAN], false, false, 'true', + ), + new SlashCommandNamedArgument( + 'chats', 'Rename char in all previous chats', [ARGUMENT_TYPE.BOOLEAN], false, false, '', + ), + ], + unnamedArgumentList: [ + new SlashCommandArgument( + 'new char name', [ARGUMENT_TYPE.STRING], true, + ), + ], + helpString: 'Renames the current character.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'sysgen', + callback: generateSystemMessage, + unnamedArgumentList: [ + new SlashCommandArgument( + 'prompt', [ARGUMENT_TYPE.STRING], true, + ), + ], + helpString: 'Generates a system message using a specified prompt.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'ask', + callback: askCharacter, + namedArgumentList: [ + SlashCommandNamedArgument.fromProps({ + name: 'name', + description: 'character name', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: true, + enumProvider: commonEnumProviders.characters('character'), + }), + ], + unnamedArgumentList: [ + new SlashCommandArgument( + 'prompt', [ARGUMENT_TYPE.STRING], true, false, + ), + ], + helpString: 'Asks a specified character card a prompt. Character name must be provided in a named argument.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'delname', + callback: deleteMessagesByNameCallback, + namedArgumentList: [], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'name', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: true, + enumProvider: commonEnumProviders.characters('character'), + }), + ], + aliases: ['cancel'], + helpString: `
Deletes all messages attributed to a specified name.
@@ -444,41 +444,41 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'send', - callback: sendUserMessageCallback, - namedArgumentList: [ - new SlashCommandNamedArgument( - 'compact', - 'whether to use a compact layout', - [ARGUMENT_TYPE.BOOLEAN], - false, - false, - 'false', - ), - SlashCommandNamedArgument.fromProps({ - name: 'at', - description: 'position to insert the message', - typeList: [ARGUMENT_TYPE.NUMBER], - enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), - }), - SlashCommandNamedArgument.fromProps({ - name: 'name', - description: 'display name', - typeList: [ARGUMENT_TYPE.STRING], - defaultValue: '{{user}}', - enumProvider: commonEnumProviders.characters('character'), - }), - ], - unnamedArgumentList: [ - new SlashCommandArgument( - 'text', - [ARGUMENT_TYPE.STRING], - true, - ), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'send', + callback: sendUserMessageCallback, + namedArgumentList: [ + new SlashCommandNamedArgument( + 'compact', + 'whether to use a compact layout', + [ARGUMENT_TYPE.BOOLEAN], + false, + false, + 'false', + ), + SlashCommandNamedArgument.fromProps({ + name: 'at', + description: 'position to insert the message', + typeList: [ARGUMENT_TYPE.NUMBER], + enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), + }), + SlashCommandNamedArgument.fromProps({ + name: 'name', + description: 'display name', + typeList: [ARGUMENT_TYPE.STRING], + defaultValue: '{{user}}', + enumProvider: commonEnumProviders.characters('character'), + }), + ], + unnamedArgumentList: [ + new SlashCommandArgument( + 'text', + [ARGUMENT_TYPE.STRING], + true, + ), + ], + helpString: `
Adds a user message to the chat log without triggering a generation.
@@ -500,29 +500,29 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'trigger', - callback: triggerGenerationCallback, - namedArgumentList: [ - new SlashCommandNamedArgument( - 'await', - 'Whether to await for the triggered generation before continuing', - [ARGUMENT_TYPE.BOOLEAN], - false, - false, - 'false', - ), - ], - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'group member index (starts with 0) or name', - typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], - isRequired: false, - enumProvider: commonEnumProviders.groupMembers(), - }), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'trigger', + callback: triggerGenerationCallback, + namedArgumentList: [ + new SlashCommandNamedArgument( + 'await', + 'Whether to await for the triggered generation before continuing', + [ARGUMENT_TYPE.BOOLEAN], + false, + false, + 'false', + ), + ], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'group member index (starts with 0) or name', + typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], + isRequired: false, + enumProvider: commonEnumProviders.groupMembers(), + }), + ], + helpString: `
Triggers a message generation. If in group, can trigger a message for the specified group member index or name.
@@ -530,74 +530,74 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ If await=true named argument is passed, the command will await for the triggered generation before continuing. `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'hide', - callback: hideMessageCallback, - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'message index (starts with 0) or range', - typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.RANGE], - isRequired: true, - enumProvider: commonEnumProviders.messages(), - }), - ], - helpString: 'Hides a chat message from the prompt.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'unhide', - callback: unhideMessageCallback, - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'message index (starts with 0) or range', - typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.RANGE], - isRequired: true, - enumProvider: commonEnumProviders.messages(), - }), - ], - helpString: 'Unhides a message from the prompt.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'member-disable', - callback: disableGroupMemberCallback, - aliases: ['disable', 'disablemember', 'memberdisable'], - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'member index (starts with 0) or name', - typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], - isRequired: true, - enumProvider: commonEnumProviders.groupMembers(), - }), - ], - helpString: 'Disables a group member from being drafted for replies.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'member-enable', - aliases: ['enable', 'enablemember', 'memberenable'], - callback: enableGroupMemberCallback, - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'member index (starts with 0) or name', - typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], - isRequired: true, - enumProvider: commonEnumProviders.groupMembers(), - }), - ], - helpString: 'Enables a group member to be drafted for replies.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'member-add', - callback: addGroupMemberCallback, - aliases: ['addmember', 'memberadd'], - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'character name', - typeList: [ARGUMENT_TYPE.STRING], - isRequired: true, - enumProvider: () => selected_group ? commonEnumProviders.characters('character')() : [], - }), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'hide', + callback: hideMessageCallback, + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'message index (starts with 0) or range', + typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.RANGE], + isRequired: true, + enumProvider: commonEnumProviders.messages(), + }), + ], + helpString: 'Hides a chat message from the prompt.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'unhide', + callback: unhideMessageCallback, + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'message index (starts with 0) or range', + typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.RANGE], + isRequired: true, + enumProvider: commonEnumProviders.messages(), + }), + ], + helpString: 'Unhides a message from the prompt.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'member-disable', + callback: disableGroupMemberCallback, + aliases: ['disable', 'disablemember', 'memberdisable'], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'member index (starts with 0) or name', + typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], + isRequired: true, + enumProvider: commonEnumProviders.groupMembers(), + }), + ], + helpString: 'Disables a group member from being drafted for replies.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'member-enable', + aliases: ['enable', 'enablemember', 'memberenable'], + callback: enableGroupMemberCallback, + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'member index (starts with 0) or name', + typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], + isRequired: true, + enumProvider: commonEnumProviders.groupMembers(), + }), + ], + helpString: 'Enables a group member to be drafted for replies.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'member-add', + callback: addGroupMemberCallback, + aliases: ['addmember', 'memberadd'], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'character name', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: true, + enumProvider: () => selected_group ? commonEnumProviders.characters('character')() : [], + }), + ], + helpString: `
Adds a new group member to the group chat.
@@ -610,20 +610,20 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'member-remove', - callback: removeGroupMemberCallback, - aliases: ['removemember', 'memberremove'], - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'member index (starts with 0) or name', - typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], - isRequired: true, - enumProvider: commonEnumProviders.groupMembers(), - }), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'member-remove', + callback: removeGroupMemberCallback, + aliases: ['removemember', 'memberremove'], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'member index (starts with 0) or name', + typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], + isRequired: true, + enumProvider: commonEnumProviders.groupMembers(), + }), + ], + helpString: `
Removes a group member from the group chat.
@@ -637,47 +637,47 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'member-up', - callback: moveGroupMemberUpCallback, - aliases: ['upmember', 'memberup'], - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'member index (starts with 0) or name', - typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], - isRequired: true, - enumProvider: commonEnumProviders.groupMembers(), - }), - ], - helpString: 'Moves a group member up in the group chat list.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'member-down', - callback: moveGroupMemberDownCallback, - aliases: ['downmember', 'memberdown'], - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'member index (starts with 0) or name', - typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], - isRequired: true, - enumProvider: commonEnumProviders.groupMembers(), - }), - ], - helpString: 'Moves a group member down in the group chat list.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'peek', - callback: peekCallback, - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'member index (starts with 0) or name', - typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], - isRequired: true, - enumProvider: commonEnumProviders.groupMembers(), - }), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'member-up', + callback: moveGroupMemberUpCallback, + aliases: ['upmember', 'memberup'], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'member index (starts with 0) or name', + typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], + isRequired: true, + enumProvider: commonEnumProviders.groupMembers(), + }), + ], + helpString: 'Moves a group member up in the group chat list.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'member-down', + callback: moveGroupMemberDownCallback, + aliases: ['downmember', 'memberdown'], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'member index (starts with 0) or name', + typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], + isRequired: true, + enumProvider: commonEnumProviders.groupMembers(), + }), + ], + helpString: 'Moves a group member down in the group chat list.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'peek', + callback: peekCallback, + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'member index (starts with 0) or name', + typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.STRING], + isRequired: true, + enumProvider: commonEnumProviders.groupMembers(), + }), + ], + helpString: `
Shows a group member character card without switching chats.
@@ -691,22 +691,22 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'delswipe', - callback: deleteSwipeCallback, - aliases: ['swipedel'], - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: '1-based swipe id', - typeList: [ARGUMENT_TYPE.NUMBER], - isRequired: true, - enumProvider: () => Array.isArray(chat[chat.length - 1]?.swipes) ? - chat[chat.length - 1].swipes.map((/** @type {string} */ swipe, /** @type {number} */ i) => new SlashCommandEnumValue(String(i + 1), swipe, enumTypes.enum, enumIcons.message)) - : [], - }), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'delswipe', + callback: deleteSwipeCallback, + aliases: ['swipedel'], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: '1-based swipe id', + typeList: [ARGUMENT_TYPE.NUMBER], + isRequired: true, + enumProvider: () => Array.isArray(chat[chat.length - 1]?.swipes) ? + chat[chat.length - 1].swipes.map((/** @type {string} */ swipe, /** @type {number} */ i) => new SlashCommandEnumValue(String(i + 1), swipe, enumTypes.enum, enumIcons.message)) + : [], + }), + ], + helpString: `
Deletes a swipe from the last chat message. If swipe id is not provided, it deletes the current swipe.
@@ -724,34 +724,34 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'echo', - callback: echoCallback, - returns: 'the text', - namedArgumentList: [ - new SlashCommandNamedArgument( - 'title', 'title of the toast message', [ARGUMENT_TYPE.STRING], false, - ), - SlashCommandNamedArgument.fromProps({ - name: 'severity', - description: 'severity level of the toast message', - typeList: [ARGUMENT_TYPE.STRING], - defaultValue: 'info', - enumProvider: () => [ - new SlashCommandEnumValue('info', 'info', enumTypes.macro, 'ℹ️'), - new SlashCommandEnumValue('warning', 'warning', enumTypes.enum, '⚠️'), - new SlashCommandEnumValue('error', 'error', enumTypes.enum, '❗'), - new SlashCommandEnumValue('success', 'success', enumTypes.enum, '✅'), - ], - }), - ], - unnamedArgumentList: [ - new SlashCommandArgument( - 'text', [ARGUMENT_TYPE.STRING], true, - ), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'echo', + callback: echoCallback, + returns: 'the text', + namedArgumentList: [ + new SlashCommandNamedArgument( + 'title', 'title of the toast message', [ARGUMENT_TYPE.STRING], false, + ), + SlashCommandNamedArgument.fromProps({ + name: 'severity', + description: 'severity level of the toast message', + typeList: [ARGUMENT_TYPE.STRING], + defaultValue: 'info', + enumProvider: () => [ + new SlashCommandEnumValue('info', 'info', enumTypes.macro, 'ℹ️'), + new SlashCommandEnumValue('warning', 'warning', enumTypes.enum, '⚠️'), + new SlashCommandEnumValue('error', 'error', enumTypes.enum, '❗'), + new SlashCommandEnumValue('success', 'success', enumTypes.enum, '✅'), + ], + }), + ], + unnamedArgumentList: [ + new SlashCommandArgument( + 'text', [ARGUMENT_TYPE.STRING], true, + ), + ], + helpString: `
Echoes the provided text to a toast message. Useful for pipes debugging.
@@ -764,42 +764,42 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'gen', - callback: generateCallback, - returns: 'generated text', - namedArgumentList: [ - new SlashCommandNamedArgument( - 'lock', 'lock user input during generation', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(), - ), - SlashCommandNamedArgument.fromProps({ - name: 'name', - description: 'in-prompt name for instruct mode', - typeList: [ARGUMENT_TYPE.STRING], - defaultValue: 'System', - enumProvider: () => [...commonEnumProviders.characters('character')(), new SlashCommandEnumValue('System', null, enumTypes.enum, enumIcons.assistant)], - forceEnum: false, - }), - new SlashCommandNamedArgument( - 'length', 'API response length in tokens', [ARGUMENT_TYPE.NUMBER], false, - ), - SlashCommandNamedArgument.fromProps({ - name: 'as', - description: 'role of the output prompt', - typeList: [ARGUMENT_TYPE.STRING], - enumList: [ - new SlashCommandEnumValue('system', null, enumTypes.enum, enumIcons.assistant), - new SlashCommandEnumValue('char', null, enumTypes.enum, enumIcons.character), - ], - }), - ], - unnamedArgumentList: [ - new SlashCommandArgument( - 'prompt', [ARGUMENT_TYPE.STRING], true, - ), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'gen', + callback: generateCallback, + returns: 'generated text', + namedArgumentList: [ + new SlashCommandNamedArgument( + 'lock', 'lock user input during generation', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(), + ), + SlashCommandNamedArgument.fromProps({ + name: 'name', + description: 'in-prompt name for instruct mode', + typeList: [ARGUMENT_TYPE.STRING], + defaultValue: 'System', + enumProvider: () => [...commonEnumProviders.characters('character')(), new SlashCommandEnumValue('System', null, enumTypes.enum, enumIcons.assistant)], + forceEnum: false, + }), + new SlashCommandNamedArgument( + 'length', 'API response length in tokens', [ARGUMENT_TYPE.NUMBER], false, + ), + SlashCommandNamedArgument.fromProps({ + name: 'as', + description: 'role of the output prompt', + typeList: [ARGUMENT_TYPE.STRING], + enumList: [ + new SlashCommandEnumValue('system', null, enumTypes.enum, enumIcons.assistant), + new SlashCommandEnumValue('char', null, enumTypes.enum, enumIcons.character), + ], + }), + ], + unnamedArgumentList: [ + new SlashCommandArgument( + 'prompt', [ARGUMENT_TYPE.STRING], true, + ), + ], + helpString: `
Generates text using the provided prompt and passes it to the next command through the pipe, optionally locking user input while generating and allowing to configure the in-prompt name for instruct mode (default = "System").
@@ -807,43 +807,43 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ "as" argument controls the role of the output prompt: system (default) or char. If "length" argument is provided as a number in tokens, allows to temporarily override an API response length. `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'genraw', - callback: generateRawCallback, - returns: 'generated text', - namedArgumentList: [ - new SlashCommandNamedArgument( - 'lock', 'lock user input during generation', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(), - ), - new SlashCommandNamedArgument( - 'instruct', 'use instruct mode', [ARGUMENT_TYPE.BOOLEAN], false, false, 'on', commonEnumProviders.boolean('onOff')(), - ), - new SlashCommandNamedArgument( - 'stop', 'one-time custom stop strings', [ARGUMENT_TYPE.LIST], false, - ), - SlashCommandNamedArgument.fromProps({ - name: 'as', - description: 'role of the output prompt', - typeList: [ARGUMENT_TYPE.STRING], - enumList: [ - new SlashCommandEnumValue('system', null, enumTypes.enum, enumIcons.assistant), - new SlashCommandEnumValue('char', null, enumTypes.enum, enumIcons.character), - ], - }), - new SlashCommandNamedArgument( - 'system', 'system prompt at the start', [ARGUMENT_TYPE.STRING], false, - ), - new SlashCommandNamedArgument( - 'length', 'API response length in tokens', [ARGUMENT_TYPE.NUMBER], false, - ), - ], - unnamedArgumentList: [ - new SlashCommandArgument( - 'prompt', [ARGUMENT_TYPE.STRING], true, - ), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'genraw', + callback: generateRawCallback, + returns: 'generated text', + namedArgumentList: [ + new SlashCommandNamedArgument( + 'lock', 'lock user input during generation', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(), + ), + new SlashCommandNamedArgument( + 'instruct', 'use instruct mode', [ARGUMENT_TYPE.BOOLEAN], false, false, 'on', commonEnumProviders.boolean('onOff')(), + ), + new SlashCommandNamedArgument( + 'stop', 'one-time custom stop strings', [ARGUMENT_TYPE.LIST], false, + ), + SlashCommandNamedArgument.fromProps({ + name: 'as', + description: 'role of the output prompt', + typeList: [ARGUMENT_TYPE.STRING], + enumList: [ + new SlashCommandEnumValue('system', null, enumTypes.enum, enumIcons.assistant), + new SlashCommandEnumValue('char', null, enumTypes.enum, enumIcons.character), + ], + }), + new SlashCommandNamedArgument( + 'system', 'system prompt at the start', [ARGUMENT_TYPE.STRING], false, + ), + new SlashCommandNamedArgument( + 'length', 'API response length in tokens', [ARGUMENT_TYPE.NUMBER], false, + ), + ], + unnamedArgumentList: [ + new SlashCommandArgument( + 'prompt', [ARGUMENT_TYPE.STRING], true, + ), + ], + helpString: `
Generates text using the provided prompt and passes it to the next command through the pipe, optionally locking user input while generating. Does not include chat history or character card.
@@ -860,55 +860,55 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ If "length" argument is provided as a number in tokens, allows to temporarily override an API response length. `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'addswipe', - callback: addSwipeCallback, - aliases: ['swipeadd'], - unnamedArgumentList: [ - new SlashCommandArgument( - 'text', [ARGUMENT_TYPE.STRING], true, - ), - ], - helpString: 'Adds a swipe to the last chat message.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'abort', - callback: abortCallback, - namedArgumentList: [ - SlashCommandNamedArgument.fromProps({ - name: 'quiet', - description: 'Whether to suppress the toast message notifying about the /abort call.', - typeList: [ARGUMENT_TYPE.BOOLEAN], - defaultValue: 'true', - }), - ], - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'The reason for aborting command execution. Shown when quiet=false', - typeList: [ARGUMENT_TYPE.STRING], - }), - ], - helpString: 'Aborts the slash command batch execution.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'fuzzy', - callback: fuzzyCallback, - returns: 'first matching item', - namedArgumentList: [ - new SlashCommandNamedArgument( - 'list', 'list of items to match against', [ARGUMENT_TYPE.LIST], true, - ), - new SlashCommandNamedArgument( - 'threshold', 'fuzzy match threshold (0.0 to 1.0)', [ARGUMENT_TYPE.NUMBER], false, false, '0.4', - ), - ], - unnamedArgumentList: [ - new SlashCommandArgument( - 'text to search', [ARGUMENT_TYPE.STRING], true, - ), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'addswipe', + callback: addSwipeCallback, + aliases: ['swipeadd'], + unnamedArgumentList: [ + new SlashCommandArgument( + 'text', [ARGUMENT_TYPE.STRING], true, + ), + ], + helpString: 'Adds a swipe to the last chat message.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'abort', + callback: abortCallback, + namedArgumentList: [ + SlashCommandNamedArgument.fromProps({ + name: 'quiet', + description: 'Whether to suppress the toast message notifying about the /abort call.', + typeList: [ARGUMENT_TYPE.BOOLEAN], + defaultValue: 'true', + }), + ], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'The reason for aborting command execution. Shown when quiet=false', + typeList: [ARGUMENT_TYPE.STRING], + }), + ], + helpString: 'Aborts the slash command batch execution.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'fuzzy', + callback: fuzzyCallback, + returns: 'first matching item', + namedArgumentList: [ + new SlashCommandNamedArgument( + 'list', 'list of items to match against', [ARGUMENT_TYPE.LIST], true, + ), + new SlashCommandNamedArgument( + 'threshold', 'fuzzy match threshold (0.0 to 1.0)', [ARGUMENT_TYPE.NUMBER], false, false, '0.4', + ), + ], + unnamedArgumentList: [ + new SlashCommandArgument( + 'text to search', [ARGUMENT_TYPE.STRING], true, + ), + ], + helpString: `
Performs a fuzzy match of each item in the list against the text to search. If any item matches, then its name is returned. If no item matches the text, no value is returned. @@ -930,23 +930,23 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
`, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'pass', - callback: (_, arg) => { - // We do not support arrays of closures. Arrays of strings will be send as JSON - if (Array.isArray(arg) && arg.some(x => x instanceof SlashCommandClosure)) throw new Error('Command /pass does not support multiple closures'); - if (Array.isArray(arg)) return JSON.stringify(arg); - return arg; - }, - returns: 'the provided value', - unnamedArgumentList: [ - new SlashCommandArgument( - 'text', [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.BOOLEAN, ARGUMENT_TYPE.LIST, ARGUMENT_TYPE.DICTIONARY, ARGUMENT_TYPE.CLOSURE], true, - ), - ], - aliases: ['return'], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'pass', + callback: (_, arg) => { + // We do not support arrays of closures. Arrays of strings will be send as JSON + if (Array.isArray(arg) && arg.some(x => x instanceof SlashCommandClosure)) throw new Error('Command /pass does not support multiple closures'); + if (Array.isArray(arg)) return JSON.stringify(arg); + return arg; + }, + returns: 'the provided value', + unnamedArgumentList: [ + new SlashCommandArgument( + 'text', [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.BOOLEAN, ARGUMENT_TYPE.LIST, ARGUMENT_TYPE.DICTIONARY, ARGUMENT_TYPE.CLOSURE], true, + ), + ], + aliases: ['return'], + helpString: `
/pass (text) – passes the text to the next command through the pipe.
@@ -957,17 +957,17 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'delay', - callback: delayCallback, - aliases: ['wait', 'sleep'], - unnamedArgumentList: [ - new SlashCommandArgument( - 'milliseconds', [ARGUMENT_TYPE.NUMBER], true, - ), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'delay', + callback: delayCallback, + aliases: ['wait', 'sleep'], + unnamedArgumentList: [ + new SlashCommandArgument( + 'milliseconds', [ARGUMENT_TYPE.NUMBER], true, + ), + ], + helpString: `
Delays the next command in the pipe by the specified number of milliseconds.
@@ -980,101 +980,101 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'input', - aliases: ['prompt'], - callback: inputCallback, - returns: 'user input', - namedArgumentList: [ - new SlashCommandNamedArgument( - 'default', 'default value of the input field', [ARGUMENT_TYPE.STRING], false, false, '"string"', - ), - new SlashCommandNamedArgument( - 'large', 'show large input field', [ARGUMENT_TYPE.BOOLEAN], false, false, 'off', commonEnumProviders.boolean('onOff')(), - ), - new SlashCommandNamedArgument( - 'wide', 'show wide input field', [ARGUMENT_TYPE.BOOLEAN], false, false, 'off', commonEnumProviders.boolean('onOff')(), - ), - new SlashCommandNamedArgument( - 'okButton', 'text for the ok button', [ARGUMENT_TYPE.STRING], false, - ), - new SlashCommandNamedArgument( - 'rows', 'number of rows for the input field', [ARGUMENT_TYPE.NUMBER], false, - ), - ], - unnamedArgumentList: [ - new SlashCommandArgument( - 'text to display', [ARGUMENT_TYPE.STRING], false, - ), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'input', + aliases: ['prompt'], + callback: inputCallback, + returns: 'user input', + namedArgumentList: [ + new SlashCommandNamedArgument( + 'default', 'default value of the input field', [ARGUMENT_TYPE.STRING], false, false, '"string"', + ), + new SlashCommandNamedArgument( + 'large', 'show large input field', [ARGUMENT_TYPE.BOOLEAN], false, false, 'off', commonEnumProviders.boolean('onOff')(), + ), + new SlashCommandNamedArgument( + 'wide', 'show wide input field', [ARGUMENT_TYPE.BOOLEAN], false, false, 'off', commonEnumProviders.boolean('onOff')(), + ), + new SlashCommandNamedArgument( + 'okButton', 'text for the ok button', [ARGUMENT_TYPE.STRING], false, + ), + new SlashCommandNamedArgument( + 'rows', 'number of rows for the input field', [ARGUMENT_TYPE.NUMBER], false, + ), + ], + unnamedArgumentList: [ + new SlashCommandArgument( + 'text to display', [ARGUMENT_TYPE.STRING], false, + ), + ], + helpString: `
Shows a popup with the provided text and an input field. The default argument is the default value of the input field, and the text argument is the text to display.
`, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'run', - aliases: ['call', 'exec'], - callback: runCallback, - returns: 'result of the executed closure of QR', - namedArgumentList: [ - new SlashCommandNamedArgument( - 'args', 'named arguments', [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.BOOLEAN, ARGUMENT_TYPE.LIST, ARGUMENT_TYPE.DICTIONARY], false, true, - ), - ], - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'scoped variable or qr label', - typeList: [ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.STRING], - isRequired: true, - enumProvider: () => [ - ...commonEnumProviders.variables('scope')(), - ...(typeof window['qrEnumProviderExecutables'] === 'function') ? window['qrEnumProviderExecutables']() : [], - ], - }), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'run', + aliases: ['call', 'exec'], + callback: runCallback, + returns: 'result of the executed closure of QR', + namedArgumentList: [ + new SlashCommandNamedArgument( + 'args', 'named arguments', [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.BOOLEAN, ARGUMENT_TYPE.LIST, ARGUMENT_TYPE.DICTIONARY], false, true, + ), + ], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'scoped variable or qr label', + typeList: [ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.STRING], + isRequired: true, + enumProvider: () => [ + ...commonEnumProviders.variables('scope')(), + ...(typeof window['qrEnumProviderExecutables'] === 'function') ? window['qrEnumProviderExecutables']() : [], + ], + }), + ], + helpString: `
Runs a closure from a scoped variable, or a Quick Reply with the specified name from a currently active preset or from another preset. Named arguments can be referenced in a QR with {{arg::key}}.
`, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'messages', - callback: getMessagesCallback, - aliases: ['message'], - namedArgumentList: [ - new SlashCommandNamedArgument( - 'names', 'show message author names', [ARGUMENT_TYPE.BOOLEAN], false, false, 'off', commonEnumProviders.boolean('onOff')(), - ), - new SlashCommandNamedArgument( - 'hidden', 'include hidden messages', [ARGUMENT_TYPE.BOOLEAN], false, false, 'on', commonEnumProviders.boolean('onOff')(), - ), - SlashCommandNamedArgument.fromProps({ - name: 'role', - description: 'filter messages by role', - typeList: [ARGUMENT_TYPE.STRING], - enumList: [ - new SlashCommandEnumValue('system', null, enumTypes.enum, enumIcons.system), - new SlashCommandEnumValue('assistant', null, enumTypes.enum, enumIcons.assistant), - new SlashCommandEnumValue('user', null, enumTypes.enum, enumIcons.user), - ], - }), - ], - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'message index (starts with 0) or range', - typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.RANGE], - isRequired: true, - enumProvider: commonEnumProviders.messages(), - }), - ], - returns: 'the specified message or range of messages as a string', - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'messages', + callback: getMessagesCallback, + aliases: ['message'], + namedArgumentList: [ + new SlashCommandNamedArgument( + 'names', 'show message author names', [ARGUMENT_TYPE.BOOLEAN], false, false, 'off', commonEnumProviders.boolean('onOff')(), + ), + new SlashCommandNamedArgument( + 'hidden', 'include hidden messages', [ARGUMENT_TYPE.BOOLEAN], false, false, 'on', commonEnumProviders.boolean('onOff')(), + ), + SlashCommandNamedArgument.fromProps({ + name: 'role', + description: 'filter messages by role', + typeList: [ARGUMENT_TYPE.STRING], + enumList: [ + new SlashCommandEnumValue('system', null, enumTypes.enum, enumIcons.system), + new SlashCommandEnumValue('assistant', null, enumTypes.enum, enumIcons.assistant), + new SlashCommandEnumValue('user', null, enumTypes.enum, enumIcons.user), + ], + }), + ], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'message index (starts with 0) or range', + typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.RANGE], + isRequired: true, + enumProvider: commonEnumProviders.messages(), + }), + ], + returns: 'the specified message or range of messages as a string', + helpString: `
Returns the specified message or range of messages as a string.
@@ -1098,16 +1098,16 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'setinput', - callback: setInputCallback, - unnamedArgumentList: [ - new SlashCommandArgument( - 'text', [ARGUMENT_TYPE.STRING], true, - ), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'setinput', + callback: setInputCallback, + unnamedArgumentList: [ + new SlashCommandArgument( + 'text', [ARGUMENT_TYPE.STRING], true, + ), + ], + helpString: `
Sets the user input to the specified text and passes it to the next command through the pipe.
@@ -1120,28 +1120,28 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'popup', - callback: popupCallback, - returns: 'popup text', - namedArgumentList: [ - new SlashCommandNamedArgument( - 'large', 'show large popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(), - ), - new SlashCommandNamedArgument( - 'wide', 'show wide popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(), - ), - new SlashCommandNamedArgument( - 'okButton', 'text for the OK button', [ARGUMENT_TYPE.STRING], false, - ), - ], - unnamedArgumentList: [ - new SlashCommandArgument( - 'text', [ARGUMENT_TYPE.STRING], true, - ), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'popup', + callback: popupCallback, + returns: 'popup text', + namedArgumentList: [ + new SlashCommandNamedArgument( + 'large', 'show large popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(), + ), + new SlashCommandNamedArgument( + 'wide', 'show wide popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(), + ), + new SlashCommandNamedArgument( + 'okButton', 'text for the OK button', [ARGUMENT_TYPE.STRING], false, + ), + ], + unnamedArgumentList: [ + new SlashCommandArgument( + 'text', [ARGUMENT_TYPE.STRING], true, + ), + ], + helpString: `
Shows a blocking popup with the specified text and buttons. Returns the popup text. @@ -1155,22 +1155,22 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
`, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'buttons', - callback: buttonsCallback, - returns: 'clicked button label', - namedArgumentList: [ - new SlashCommandNamedArgument( - 'labels', 'button labels', [ARGUMENT_TYPE.LIST], true, - ), - ], - unnamedArgumentList: [ - new SlashCommandArgument( - 'text', [ARGUMENT_TYPE.STRING], true, - ), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'buttons', + callback: buttonsCallback, + returns: 'clicked button label', + namedArgumentList: [ + new SlashCommandNamedArgument( + 'labels', 'button labels', [ARGUMENT_TYPE.LIST], true, + ), + ], + unnamedArgumentList: [ + new SlashCommandArgument( + 'text', [ARGUMENT_TYPE.STRING], true, + ), + ], + helpString: `
Shows a blocking popup with the specified text and buttons. Returns the clicked button label into the pipe or empty string if canceled. @@ -1184,32 +1184,32 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
`, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'trimtokens', - callback: trimTokensCallback, - returns: 'trimmed text', - namedArgumentList: [ - new SlashCommandNamedArgument( - 'limit', 'number of tokens to keep', [ARGUMENT_TYPE.NUMBER], true, - ), - SlashCommandNamedArgument.fromProps({ - name: 'direction', - description: 'trim direction', - typeList: [ARGUMENT_TYPE.STRING], - isRequired: true, - enumList: [ - new SlashCommandEnumValue('start', null, enumTypes.enum, '⏪'), - new SlashCommandEnumValue('end', null, enumTypes.enum, '⏩'), - ], - }), - ], - unnamedArgumentList: [ - new SlashCommandArgument( - 'text', [ARGUMENT_TYPE.STRING], false, - ), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'trimtokens', + callback: trimTokensCallback, + returns: 'trimmed text', + namedArgumentList: [ + new SlashCommandNamedArgument( + 'limit', 'number of tokens to keep', [ARGUMENT_TYPE.NUMBER], true, + ), + SlashCommandNamedArgument.fromProps({ + name: 'direction', + description: 'trim direction', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: true, + enumList: [ + new SlashCommandEnumValue('start', null, enumTypes.enum, '⏪'), + new SlashCommandEnumValue('end', null, enumTypes.enum, '⏩'), + ], + }), + ], + unnamedArgumentList: [ + new SlashCommandArgument( + 'text', [ARGUMENT_TYPE.STRING], false, + ), + ], + helpString: `
Trims the start or end of text to the specified number of tokens.
@@ -1222,17 +1222,17 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'trimstart', - callback: trimStartCallback, - returns: 'trimmed text', - unnamedArgumentList: [ - new SlashCommandArgument( - 'text', [ARGUMENT_TYPE.STRING], true, - ), - ], - helpString: ` + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'trimstart', + callback: trimStartCallback, + returns: 'trimmed text', + unnamedArgumentList: [ + new SlashCommandArgument( + 'text', [ARGUMENT_TYPE.STRING], true, + ), + ], + helpString: `
Trims the text to the start of the first full sentence.
@@ -1245,148 +1245,149 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ `, -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'trimend', - callback: trimEndCallback, - returns: 'trimmed text', - unnamedArgumentList: [ - new SlashCommandArgument( - 'text', [ARGUMENT_TYPE.STRING], true, - ), - ], - helpString: 'Trims the text to the end of the last full sentence.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'inject', - callback: injectCallback, - namedArgumentList: [ - SlashCommandNamedArgument.fromProps({ - name: 'id', - description: 'injection ID or variable name pointing to ID', - typeList: [ARGUMENT_TYPE.STRING], - isRequired: true, - enumProvider: commonEnumProviders.injects, - }), - new SlashCommandNamedArgument( - 'position', 'injection position', [ARGUMENT_TYPE.STRING], false, false, 'after', ['before', 'after', 'chat'], - ), - new SlashCommandNamedArgument( - 'depth', 'injection depth', [ARGUMENT_TYPE.NUMBER], false, false, '4', - ), - new SlashCommandNamedArgument( - 'scan', 'include injection content into World Info scans', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false', - ), - SlashCommandNamedArgument.fromProps({ - name: 'role', - description: 'role for in-chat injections', - typeList: [ARGUMENT_TYPE.STRING], - isRequired: false, - enumList: [ - new SlashCommandEnumValue('system', null, enumTypes.enum, enumIcons.system), - new SlashCommandEnumValue('assistant', null, enumTypes.enum, enumIcons.assistant), - new SlashCommandEnumValue('user', null, enumTypes.enum, enumIcons.user), - ], - }), - new SlashCommandNamedArgument( - 'ephemeral', 'remove injection after generation', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false', - ), - ], - unnamedArgumentList: [ - new SlashCommandArgument( - 'text', [ARGUMENT_TYPE.STRING], false, - ), - ], - helpString: 'Injects a text into the LLM prompt for the current chat. Requires a unique injection ID. Positions: "before" main prompt, "after" main prompt, in-"chat" (default: after). Depth: injection depth for the prompt (default: 4). Role: role for in-chat injections (default: system). Scan: include injection content into World Info scans (default: false).', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'listinjects', - callback: listInjectsCallback, - helpString: 'Lists all script injections for the current chat.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'flushinject', - aliases: ['flushinjects'], - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'injection ID or a variable name pointing to ID', - typeList: [ARGUMENT_TYPE.STRING], - defaultValue: '', - enumProvider: commonEnumProviders.injects, - }), - ], - callback: flushInjectsCallback, - helpString: 'Removes a script injection for the current chat. If no ID is provided, removes all script injections.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'tokens', - callback: (_, text) => { - if (text instanceof SlashCommandClosure || Array.isArray(text)) throw new Error('Unnamed argument cannot be a closure for command /tokens'); - return getTokenCountAsync(text).then(count => String(count)); - }, - returns: 'number of tokens', - unnamedArgumentList: [ - new SlashCommandArgument( - 'text', [ARGUMENT_TYPE.STRING], true, - ), - ], - helpString: 'Counts the number of tokens in the provided text.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'model', - callback: modelCallback, - returns: 'current model', - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'model name', - typeList: [ARGUMENT_TYPE.STRING], - enumProvider: () => getModelOptions()?.options.map(option => new SlashCommandEnumValue(option.value, option.value !== option.text ? option.text : null)), - }), - ], - helpString: 'Sets the model for the current API. Gets the current model name if no argument is provided.', -})); -SlashCommandParser.addCommandObject(SlashCommand.fromProps({ - name: 'setpromptentry', - aliases: ['setpromptentries'], - callback: setPromptEntryCallback, - namedArgumentList: [ - SlashCommandNamedArgument.fromProps({ - name: 'identifier', - description: 'Prompt entry identifier(s) to target', - typeList: [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.LIST], - acceptsMultiple: true, - enumProvider: () => { - const promptManager = setupChatCompletionPromptManager(oai_settings); - const prompts = promptManager.serviceSettings.prompts; - return prompts.map(prompt => new SlashCommandEnumValue(prompt.identifier, prompt.name, enumTypes.enum)); - }, - }), - SlashCommandNamedArgument.fromProps({ - name: 'name', - description: 'Prompt entry name(s) to target', - typeList: [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.LIST], - acceptsMultiple: true, - enumProvider: () => { - const promptManager = setupChatCompletionPromptManager(oai_settings); - const prompts = promptManager.serviceSettings.prompts; - return prompts.map(prompt => new SlashCommandEnumValue(prompt.name, prompt.identifier, enumTypes.enum)); - }, - }), - ], - unnamedArgumentList: [ - SlashCommandArgument.fromProps({ - description: 'Set entry/entries on or off', - typeList: [ARGUMENT_TYPE.STRING], - isRequired: true, - acceptsMultiple: false, - defaultValue: 'toggle', // unnamed arguments don't support default values yet - enumList: commonEnumProviders.boolean('onOffToggle')(), - }), - ], - helpString: 'Sets the specified prompt manager entry/entries on or off.', -})); + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'trimend', + callback: trimEndCallback, + returns: 'trimmed text', + unnamedArgumentList: [ + new SlashCommandArgument( + 'text', [ARGUMENT_TYPE.STRING], true, + ), + ], + helpString: 'Trims the text to the end of the last full sentence.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'inject', + callback: injectCallback, + namedArgumentList: [ + SlashCommandNamedArgument.fromProps({ + name: 'id', + description: 'injection ID or variable name pointing to ID', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: true, + enumProvider: commonEnumProviders.injects, + }), + new SlashCommandNamedArgument( + 'position', 'injection position', [ARGUMENT_TYPE.STRING], false, false, 'after', ['before', 'after', 'chat'], + ), + new SlashCommandNamedArgument( + 'depth', 'injection depth', [ARGUMENT_TYPE.NUMBER], false, false, '4', + ), + new SlashCommandNamedArgument( + 'scan', 'include injection content into World Info scans', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false', + ), + SlashCommandNamedArgument.fromProps({ + name: 'role', + description: 'role for in-chat injections', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: false, + enumList: [ + new SlashCommandEnumValue('system', null, enumTypes.enum, enumIcons.system), + new SlashCommandEnumValue('assistant', null, enumTypes.enum, enumIcons.assistant), + new SlashCommandEnumValue('user', null, enumTypes.enum, enumIcons.user), + ], + }), + new SlashCommandNamedArgument( + 'ephemeral', 'remove injection after generation', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false', + ), + ], + unnamedArgumentList: [ + new SlashCommandArgument( + 'text', [ARGUMENT_TYPE.STRING], false, + ), + ], + helpString: 'Injects a text into the LLM prompt for the current chat. Requires a unique injection ID. Positions: "before" main prompt, "after" main prompt, in-"chat" (default: after). Depth: injection depth for the prompt (default: 4). Role: role for in-chat injections (default: system). Scan: include injection content into World Info scans (default: false).', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'listinjects', + callback: listInjectsCallback, + helpString: 'Lists all script injections for the current chat.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'flushinject', + aliases: ['flushinjects'], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'injection ID or a variable name pointing to ID', + typeList: [ARGUMENT_TYPE.STRING], + defaultValue: '', + enumProvider: commonEnumProviders.injects, + }), + ], + callback: flushInjectsCallback, + helpString: 'Removes a script injection for the current chat. If no ID is provided, removes all script injections.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'tokens', + callback: (_, text) => { + if (text instanceof SlashCommandClosure || Array.isArray(text)) throw new Error('Unnamed argument cannot be a closure for command /tokens'); + return getTokenCountAsync(text).then(count => String(count)); + }, + returns: 'number of tokens', + unnamedArgumentList: [ + new SlashCommandArgument( + 'text', [ARGUMENT_TYPE.STRING], true, + ), + ], + helpString: 'Counts the number of tokens in the provided text.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'model', + callback: modelCallback, + returns: 'current model', + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'model name', + typeList: [ARGUMENT_TYPE.STRING], + enumProvider: () => getModelOptions()?.options.map(option => new SlashCommandEnumValue(option.value, option.value !== option.text ? option.text : null)), + }), + ], + helpString: 'Sets the model for the current API. Gets the current model name if no argument is provided.', + })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'setpromptentry', + aliases: ['setpromptentries'], + callback: setPromptEntryCallback, + namedArgumentList: [ + SlashCommandNamedArgument.fromProps({ + name: 'identifier', + description: 'Prompt entry identifier(s) to target', + typeList: [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.LIST], + acceptsMultiple: true, + enumProvider: () => { + const promptManager = setupChatCompletionPromptManager(oai_settings); + const prompts = promptManager.serviceSettings.prompts; + return prompts.map(prompt => new SlashCommandEnumValue(prompt.identifier, prompt.name, enumTypes.enum)); + }, + }), + SlashCommandNamedArgument.fromProps({ + name: 'name', + description: 'Prompt entry name(s) to target', + typeList: [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.LIST], + acceptsMultiple: true, + enumProvider: () => { + const promptManager = setupChatCompletionPromptManager(oai_settings); + const prompts = promptManager.serviceSettings.prompts; + return prompts.map(prompt => new SlashCommandEnumValue(prompt.name, prompt.identifier, enumTypes.enum)); + }, + }), + ], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'Set entry/entries on or off', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: true, + acceptsMultiple: false, + defaultValue: 'toggle', // unnamed arguments don't support default values yet + enumList: commonEnumProviders.boolean('onOffToggle')(), + }), + ], + helpString: 'Sets the specified prompt manager entry/entries on or off.', + })); -registerVariableCommands(); + registerVariableCommands(); +} const NARRATOR_NAME_KEY = 'narrator_name'; const NARRATOR_NAME_DEFAULT = 'System'; From 1d6f0386013991b6acd56e3c6d4a121a513387cf Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sat, 29 Jun 2024 02:16:36 +0200 Subject: [PATCH 3/8] Add optional args to /echo command --- public/scripts/slash-commands.js | 77 ++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 3573453bd..6abec1972 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -745,6 +745,32 @@ export function initDefaultSlashCommands() { new SlashCommandEnumValue('success', 'success', enumTypes.enum, '✅'), ], }), + SlashCommandNamedArgument.fromProps({ + name: 'timeOut', + description: 'time in milliseconds to display the toast message. Set this and \'extendedTimeout\' to 0 to show indefinitely until dismissed.', + typeList: [ARGUMENT_TYPE.NUMBER], + defaultValue: `${toastr.options.timeOut}`, + }), + SlashCommandNamedArgument.fromProps({ + name: 'extendedTimeout', + description: 'time in milliseconds to display the toast message. Set this and \'timeOut\' to 0 to show indefinitely until dismissed.', + typeList: [ARGUMENT_TYPE.NUMBER], + defaultValue: `${toastr.options.extendedTimeOut}`, + }), + SlashCommandNamedArgument.fromProps({ + name: 'preventDuplicates', + description: 'prevent duplicate toasts with the same message from being displayed.', + typeList: [ARGUMENT_TYPE.BOOLEAN], + defaultValue: 'false', + enumList: commonEnumProviders.boolean('trueFalse')(), + }), + SlashCommandNamedArgument.fromProps({ + name: 'awaitDismissal', + description: 'wait for the toast to be dismissed before continuing.', + typeList: [ARGUMENT_TYPE.BOOLEAN], + defaultValue: 'false', + enumList: commonEnumProviders.boolean('trueFalse')(), + }), ], unnamedArgumentList: [ new SlashCommandArgument( @@ -1939,32 +1965,67 @@ async function generateCallback(args, value) { } } +/** + * + * @param {{title?: string, severity?: string, timeOut?: string, extendedTimeOut?: string, preventDuplicates?: string, awaitDismissal?: string}} args - named arguments from the slash command + * @param {string} value - The string to echo (unnamed argument from the slash command) + * @returns {Promise} The text that was echoed + */ async function echoCallback(args, value) { // Note: We don't need to sanitize input, as toastr is set up by default to escape HTML via toastr options if (value === '') { console.warn('WARN: No argument provided for /echo command'); - return; + return ''; } - const title = args?.title !== undefined && typeof args?.title === 'string' ? args.title : undefined; - const severity = args?.severity !== undefined && typeof args?.severity === 'string' ? args.severity : 'info'; + + if (args.severity && !['error', 'warning', 'success', 'info'].includes(args.severity)) { + toastr.warning(`Invalid severity provided for /echo command: ${args.severity}`); + args.severity = null; + } + + const title = args.title ? args.title : undefined; + const severity = args.severity ? args.severity : 'info'; + + /** @type {ToastrOptions} */ + const options = {}; + if (args.timeOut && !isNaN(parseInt(args.timeOut))) options.timeOut = parseInt(args.timeOut); + if (args.extendedTimeOut && !isNaN(parseInt(args.extendedTimeOut))) options.extendedTimeOut = parseInt(args.extendedTimeOut); + if (isTrueBoolean(args.preventDuplicates)) options.preventDuplicates = true; + + // Prepare possible await handling + let awaitDismissal = isTrueBoolean(args.awaitDismissal); + let resolveToastDismissal; + + if (awaitDismissal) { + options.onHidden = () => resolveToastDismissal(value); + } + switch (severity) { case 'error': - toastr.error(value, title); + toastr.error(value, title, options); break; case 'warning': - toastr.warning(value, title); + toastr.warning(value, title, options); break; case 'success': - toastr.success(value, title); + toastr.success(value, title, options); break; case 'info': default: - toastr.info(value, title); + toastr.info(value, title, options); break; } - return value; + + if (awaitDismissal) { + return new Promise((resolve) => { + resolveToastDismissal = resolve; + }); + } else { + return value; + } } + async function addSwipeCallback(_, arg) { const lastMessage = chat[chat.length - 1]; From 5c3b799d6589539d6804b74733bad6f1a7dedd9e Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sat, 29 Jun 2024 02:24:20 +0200 Subject: [PATCH 4/8] Fix naming inconsistencies --- public/scripts/slash-commands.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 6abec1972..cfc206e89 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -746,14 +746,14 @@ export function initDefaultSlashCommands() { ], }), SlashCommandNamedArgument.fromProps({ - name: 'timeOut', + name: 'timeout', description: 'time in milliseconds to display the toast message. Set this and \'extendedTimeout\' to 0 to show indefinitely until dismissed.', typeList: [ARGUMENT_TYPE.NUMBER], defaultValue: `${toastr.options.timeOut}`, }), SlashCommandNamedArgument.fromProps({ name: 'extendedTimeout', - description: 'time in milliseconds to display the toast message. Set this and \'timeOut\' to 0 to show indefinitely until dismissed.', + description: 'time in milliseconds to display the toast message. Set this and \'timeout\' to 0 to show indefinitely until dismissed.', typeList: [ARGUMENT_TYPE.NUMBER], defaultValue: `${toastr.options.extendedTimeOut}`, }), @@ -1967,7 +1967,7 @@ async function generateCallback(args, value) { /** * - * @param {{title?: string, severity?: string, timeOut?: string, extendedTimeOut?: string, preventDuplicates?: string, awaitDismissal?: string}} args - named arguments from the slash command + * @param {{title?: string, severity?: string, timeout?: string, extendedTimeout?: string, preventDuplicates?: string, awaitDismissal?: string}} args - named arguments from the slash command * @param {string} value - The string to echo (unnamed argument from the slash command) * @returns {Promise} The text that was echoed */ @@ -1988,8 +1988,8 @@ async function echoCallback(args, value) { /** @type {ToastrOptions} */ const options = {}; - if (args.timeOut && !isNaN(parseInt(args.timeOut))) options.timeOut = parseInt(args.timeOut); - if (args.extendedTimeOut && !isNaN(parseInt(args.extendedTimeOut))) options.extendedTimeOut = parseInt(args.extendedTimeOut); + if (args.timeout && !isNaN(parseInt(args.timeout))) options.timeOut = parseInt(args.timeout); + if (args.extendedTimeout && !isNaN(parseInt(args.extendedTimeout))) options.extendedTimeOut = parseInt(args.extendedTimeout); if (isTrueBoolean(args.preventDuplicates)) options.preventDuplicates = true; // Prepare possible await handling From 75099d3a2260476b877d904119a0241902beeeaa Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sat, 29 Jun 2024 02:42:01 +0200 Subject: [PATCH 5/8] Fix oversight in forceEnum slash commands --- public/scripts/slash-commands/SlashCommandArgument.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/public/scripts/slash-commands/SlashCommandArgument.js b/public/scripts/slash-commands/SlashCommandArgument.js index 76642a160..02c88b7c2 100644 --- a/public/scripts/slash-commands/SlashCommandArgument.js +++ b/public/scripts/slash-commands/SlashCommandArgument.js @@ -59,7 +59,7 @@ export class SlashCommandArgument { * @param {string|SlashCommandEnumValue|(string|SlashCommandEnumValue)[]} enums * @param {(executor:SlashCommandExecutor)=>SlashCommandEnumValue[]} enumProvider function that returns auto complete options */ - constructor(description, types, isRequired = false, acceptsMultiple = false, defaultValue = null, enums = [], enumProvider = null, forceEnum = true) { + constructor(description, types, isRequired = false, acceptsMultiple = false, defaultValue = null, enums = [], enumProvider = null, forceEnum = false) { this.description = description; this.typeList = types ? Array.isArray(types) ? types : [types] : []; this.isRequired = isRequired ?? false; @@ -90,7 +90,7 @@ export class SlashCommandNamedArgument extends SlashCommandArgument { * @param {string|SlashCommandClosure} [props.defaultValue=null] default value if no value is provided * @param {string|SlashCommandEnumValue|(string|SlashCommandEnumValue)[]} [props.enumList=[]] list of accepted values * @param {(executor:SlashCommandExecutor)=>SlashCommandEnumValue[]} [props.enumProvider=null] function that returns auto complete options - * @param {boolean} [props.forceEnum=true] default: true - whether the input must match one of the enum values + * @param {boolean} [props.forceEnum=false] default: false - whether the input must match one of the enum values */ static fromProps(props) { return new SlashCommandNamedArgument( @@ -103,7 +103,7 @@ export class SlashCommandNamedArgument extends SlashCommandArgument { props.enumList ?? [], props.aliasList ?? [], props.enumProvider ?? null, - props.forceEnum ?? true, + props.forceEnum ?? false, ); } @@ -120,9 +120,9 @@ export class SlashCommandNamedArgument extends SlashCommandArgument { * @param {string|SlashCommandEnumValue|(string|SlashCommandEnumValue)[]} [enums=[]] * @param {string[]} [aliases=[]] * @param {(executor:SlashCommandExecutor)=>SlashCommandEnumValue[]} [enumProvider=null] function that returns auto complete options - * @param {boolean} [forceEnum=true] + * @param {boolean} [forceEnum=false] */ - constructor(name, description, types, isRequired = false, acceptsMultiple = false, defaultValue = null, enums = [], aliases = [], enumProvider = null, forceEnum = true) { + constructor(name, description, types, isRequired = false, acceptsMultiple = false, defaultValue = null, enums = [], aliases = [], enumProvider = null, forceEnum = false) { super(description, types, isRequired, acceptsMultiple, defaultValue, enums, enumProvider, forceEnum); this.name = name; this.aliasList = aliases ? Array.isArray(aliases) ? aliases : [aliases] : []; From f7d3a1c942b338b43f28738bb4f5b41cb4b8f6cf Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sat, 29 Jun 2024 02:52:30 +0200 Subject: [PATCH 6/8] Various commands with 'at' support depth values --- public/scripts/slash-commands.js | 41 +++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 3573453bd..3628c0142 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -177,7 +177,7 @@ export function initDefaultSlashCommands() { ), SlashCommandNamedArgument.fromProps({ name: 'at', - description: 'position to insert the message', + description: 'position to insert the message (index-based, corresponding to message id). If not set, the message will be inserted at the end of the chat.\nNegative values are accepted and will work similarly to how \'depth\' usually works. For example, -1 will insert the message right before the last message in chat.', typeList: [ARGUMENT_TYPE.NUMBER], enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), }), @@ -220,7 +220,7 @@ export function initDefaultSlashCommands() { ), SlashCommandNamedArgument.fromProps({ name: 'at', - description: 'position to insert the message', + description: 'position to insert the message (index-based, corresponding to message id). If not set, the message will be inserted at the end of the chat.\nNegative values are accepted and will work similarly to how \'depth\' usually works. For example, -1 will insert the message right before the last message in chat.', typeList: [ARGUMENT_TYPE.NUMBER], enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), }), @@ -274,7 +274,7 @@ export function initDefaultSlashCommands() { ), SlashCommandNamedArgument.fromProps({ name: 'at', - description: 'position to insert the message', + description: 'position to insert the message (index-based, corresponding to message id). If not set, the message will be inserted at the end of the chat.\nNegative values are accepted and will work similarly to how \'depth\' usually works. For example, -1 will insert the message right before the last message in chat.', typeList: [ARGUMENT_TYPE.NUMBER], enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), }), @@ -459,7 +459,7 @@ export function initDefaultSlashCommands() { ), SlashCommandNamedArgument.fromProps({ name: 'at', - description: 'position to insert the message', + description: 'position to insert the message (index-based, corresponding to message id). If not set, the message will be inserted at the end of the chat.\nNegative values are accepted and will work similarly to how \'depth\' usually works. For example, -1 will insert the message right before the last message in chat.', typeList: [ARGUMENT_TYPE.NUMBER], enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), }), @@ -2429,7 +2429,14 @@ async function sendUserMessageCallback(args, text) { text = text.trim(); const compact = isTrueBoolean(args?.compact); const bias = extractMessageBias(text); - const insertAt = Number(args?.at); + + let insertAt = Number(args?.at); + + // Convert possible depth parameter to index + if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) { + // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7) + insertAt = chat.length + insertAt; + } if ('name' in args) { const name = args.name || ''; @@ -2738,7 +2745,13 @@ export async function sendMessageAs(args, text) { }, }]; - const insertAt = Number(args.at); + let insertAt = Number(args.at); + + // Convert possible depth parameter to index + if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) { + // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7) + insertAt = chat.length + insertAt; + } if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) { chat.splice(insertAt, 0, message); @@ -2785,7 +2798,13 @@ export async function sendNarratorMessage(args, text) { }, }; - const insertAt = Number(args.at); + let insertAt = Number(args.at); + + // Convert possible depth parameter to index + if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) { + // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7) + insertAt = chat.length + insertAt; + } if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) { chat.splice(insertAt, 0, message); @@ -2867,7 +2886,13 @@ async function sendCommentMessage(args, text) { }, }; - const insertAt = Number(args.at); + let insertAt = Number(args.at); + + // Convert possible depth parameter to index + if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) { + // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7) + insertAt = chat.length + insertAt; + } if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) { chat.splice(insertAt, 0, message); From bb39e852b88eca7cc5ba5caf7ac8565ec2e285fb Mon Sep 17 00:00:00 2001 From: Risenafis <91325858+Risenafis@users.noreply.github.com> Date: Sat, 29 Jun 2024 20:15:37 +0900 Subject: [PATCH 7/8] TTS: Add support for VITS/W2V2-VITS/Bert-VITS2 (#2439) * add VITSTtsProvider * add options * fix params, drop reference_audio_path * post with body * improve preview lang * add space in label --- public/scripts/extensions/tts/index.js | 2 + public/scripts/extensions/tts/vits.js | 404 +++++++++++++++++++++++++ 2 files changed, 406 insertions(+) create mode 100644 public/scripts/extensions/tts/vits.js diff --git a/public/scripts/extensions/tts/index.js b/public/scripts/extensions/tts/index.js index 13d3718ed..3ea6f491a 100644 --- a/public/scripts/extensions/tts/index.js +++ b/public/scripts/extensions/tts/index.js @@ -10,6 +10,7 @@ import { NovelTtsProvider } from './novel.js'; import { power_user } from '../../power-user.js'; import { OpenAITtsProvider } from './openai.js'; import { XTTSTtsProvider } from './xtts.js'; +import { VITSTtsProvider } from './vits.js'; import { GSVITtsProvider } from './gsvi.js'; import { SBVits2TtsProvider } from './sbvits2.js'; import { AllTalkTtsProvider } from './alltalk.js'; @@ -83,6 +84,7 @@ const ttsProviders = { ElevenLabs: ElevenLabsTtsProvider, Silero: SileroTtsProvider, XTTSv2: XTTSTtsProvider, + VITS: VITSTtsProvider, GSVI: GSVITtsProvider, SBVits2: SBVits2TtsProvider, System: SystemTtsProvider, diff --git a/public/scripts/extensions/tts/vits.js b/public/scripts/extensions/tts/vits.js new file mode 100644 index 000000000..4cfa72953 --- /dev/null +++ b/public/scripts/extensions/tts/vits.js @@ -0,0 +1,404 @@ +import { getPreviewString, saveTtsProviderSettings } from './index.js'; + +export { VITSTtsProvider }; + +class VITSTtsProvider { + //########// + // Config // + //########// + + settings; + ready = false; + voices = []; + separator = '. '; + audioElement = document.createElement('audio'); + + /** + * Perform any text processing before passing to TTS engine. + * @param {string} text Input text + * @returns {string} Processed text + */ + processText(text) { + return text; + } + + audioFormats = ['wav', 'ogg', 'silk', 'mp3', 'flac']; + + languageLabels = { + 'Auto': 'auto', + 'Chinese': 'zh', + 'English': 'en', + 'Japanese': 'ja', + 'Korean': 'ko', + }; + + langKey2LangCode = { + 'zh': 'zh-CN', + 'en': 'en-US', + 'ja': 'ja-JP', + 'ko': 'ko-KR', + }; + + modelTypes = { + VITS: 'VITS', + W2V2_VITS: 'W2V2-VITS', + BERT_VITS2: 'BERT-VITS2', + }; + + defaultSettings = { + provider_endpoint: 'http://localhost:23456', + format: 'wav', + lang: 'auto', + length: 1.0, + noise: 0.33, + noisew: 0.4, + segment_size: 50, + streaming: false, + dim_emotion: 0, + sdp_ratio: 0.2, + emotion: 0, + text_prompt: '', + style_text: '', + style_weight: 1, + }; + + get settingsHtml() { + let html = ` + + +
+ + + Use vits-simple-api.
+ + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + + + + + + + + + + + `; + + return html; + } + + onSettingsChange() { + // Used when provider settings are updated from UI + this.settings.provider_endpoint = $('#vits_endpoint').val(); + this.settings.lang = $('#vits_lang').val(); + this.settings.format = $('#vits_format').val(); + this.settings.dim_emotion = $('#vits_dim_emotion').val(); + this.settings.text_prompt = $('#vits_text_prompt').val(); + this.settings.style_text = $('#vits_style_text').val(); + + // Update the default TTS settings based on input fields + this.settings.length = $('#vits_length').val(); + this.settings.noise = $('#vits_noise').val(); + this.settings.noisew = $('#vits_noisew').val(); + this.settings.segment_size = $('#vits_segment_size').val(); + this.settings.streaming = $('#vits_streaming').is(':checked'); + this.settings.sdp_ratio = $('#vits_sdp_ratio').val(); + this.settings.emotion = $('#vits_emotion').val(); + this.settings.style_weight = $('#vits_style_weight').val(); + + // Update the UI to reflect changes + $('#vits_length_output').text(this.settings.length); + $('#vits_noise_output').text(this.settings.noise); + $('#vits_noisew_output').text(this.settings.noisew); + $('#vits_segment_size_output').text(this.settings.segment_size); + $('#vits_sdp_ratio_output').text(this.settings.sdp_ratio); + $('#vits_emotion_output').text(this.settings.emotion); + $('#vits_style_weight_output').text(this.settings.style_weight); + + saveTtsProviderSettings(); + this.changeTTSSettings(); + } + + async loadSettings(settings) { + // Pupulate Provider UI given input settings + if (Object.keys(settings).length == 0) { + console.info('Using default TTS Provider settings'); + } + + // Only accept keys defined in defaultSettings + this.settings = this.defaultSettings; + + for (const key in settings) { + if (key in this.settings) { + this.settings[key] = settings[key]; + } else { + console.debug(`Ignoring non-user-configurable setting: ${key}`); + } + } + + // Set initial values from the settings + $('#vits_endpoint').val(this.settings.provider_endpoint); + $('#vits_lang').val(this.settings.lang); + $('#vits_format').val(this.settings.format); + $('#vits_length').val(this.settings.length); + $('#vits_noise').val(this.settings.noise); + $('#vits_noisew').val(this.settings.noisew); + $('#vits_segment_size').val(this.settings.segment_size); + $('#vits_streaming').prop('checked', this.settings.streaming); + $('#vits_dim_emotion').val(this.settings.dim_emotion); + $('#vits_sdp_ratio').val(this.settings.sdp_ratio); + $('#vits_emotion').val(this.settings.emotion); + $('#vits_text_prompt').val(this.settings.text_prompt); + $('#vits_style_text').val(this.settings.style_text); + $('#vits_style_weight').val(this.settings.style_weight); + + // Update the UI to reflect changes + $('#vits_length_output').text(this.settings.length); + $('#vits_noise_output').text(this.settings.noise); + $('#vits_noisew_output').text(this.settings.noisew); + $('#vits_segment_size_output').text(this.settings.segment_size); + $('#vits_sdp_ratio_output').text(this.settings.sdp_ratio); + $('#vits_emotion_output').text(this.settings.emotion); + $('#vits_style_weight_output').text(this.settings.style_weight); + + // Register input/change event listeners to update settings on user interaction + $('#vits_endpoint').on('input', () => { this.onSettingsChange(); }); + $('#vits_lang').on('change', () => { this.onSettingsChange(); }); + $('#vits_format').on('change', () => { this.onSettingsChange(); }); + $('#vits_length').on('change', () => { this.onSettingsChange(); }); + $('#vits_noise').on('change', () => { this.onSettingsChange(); }); + $('#vits_noisew').on('change', () => { this.onSettingsChange(); }); + $('#vits_segment_size').on('change', () => { this.onSettingsChange(); }); + $('#vits_streaming').on('change', () => { this.onSettingsChange(); }); + $('#vits_dim_emotion').on('change', () => { this.onSettingsChange(); }); + $('#vits_sdp_ratio').on('change', () => { this.onSettingsChange(); }); + $('#vits_emotion').on('change', () => { this.onSettingsChange(); }); + $('#vits_text_prompt').on('change', () => { this.onSettingsChange(); }); + $('#vits_style_text').on('change', () => { this.onSettingsChange(); }); + $('#vits_style_weight').on('change', () => { this.onSettingsChange(); }); + + await this.checkReady(); + + console.info('VITS: Settings loaded'); + } + + // Perform a simple readiness check by trying to fetch voiceIds + async checkReady() { + await Promise.allSettled([this.fetchTtsVoiceObjects(), this.changeTTSSettings()]); + } + + async onRefreshClick() { + return; + } + + //#################// + // TTS Interfaces // + //#################// + + async getVoice(voiceName) { + if (this.voices.length == 0) { + this.voices = await this.fetchTtsVoiceObjects(); + } + const match = this.voices.filter( + v => v.name == voiceName, + )[0]; + if (!match) { + throw `TTS Voice name ${voiceName} not found`; + } + return match; + } + + async getVoiceById(voiceId) { + if (this.voices.length == 0) { + this.voices = await this.fetchTtsVoiceObjects(); + } + const match = this.voices.filter( + v => v.voice_id == voiceId, + )[0]; + if (!match) { + throw `TTS Voice id ${voiceId} not found`; + } + return match; + } + + async generateTts(text, voiceId) { + const response = await this.fetchTtsGeneration(text, voiceId); + return response; + } + + //###########// + // API CALLS // + //###########// + async fetchTtsVoiceObjects() { + const response = await fetch(`${this.settings.provider_endpoint}/voice/speakers`); + if (!response.ok) { + throw new Error(`HTTP ${response.status}: ${await response.json()}`); + } + const jsonData = await response.json(); + const voices = []; + + const addVoices = (modelType) => { + jsonData[modelType].forEach(voice => { + voices.push({ + name: `[${modelType}] ${voice.name} (${voice.lang})`, + voice_id: `${modelType}&${voice.id}`, + preview_url: false, + lang: voice.lang, + }); + }); + }; + for (const key in this.modelTypes) { + addVoices(this.modelTypes[key]); + } + + this.voices = voices; // Assign to the class property + return voices; // Also return this list + } + + // Each time a parameter is changed, we change the configuration + async changeTTSSettings() { + } + + /** + * Fetch TTS generation from the API. + * @param {string} inputText Text to generate TTS for + * @param {string} voiceId Voice ID to use (model_type&speaker_id)) + * @returns {Promise} Fetch response + */ + async fetchTtsGeneration(inputText, voiceId, lang = null, forceNoStreaming = false) { + console.info(`Generating new TTS for voice_id ${voiceId}`); + + const streaming = !forceNoStreaming && this.settings.streaming; + const [model_type, speaker_id] = voiceId.split('&'); + const params = new URLSearchParams(); + params.append('text', inputText); + params.append('id', speaker_id); + if (streaming) { + params.append('streaming', streaming); + // Streaming response only supports MP3 + } + else { + params.append('format', this.settings.format); + } + params.append('lang', lang ?? this.settings.lang); + params.append('length', this.settings.length); + params.append('noise', this.settings.noise); + params.append('noisew', this.settings.noisew); + params.append('segment_size', this.settings.segment_size); + + if (model_type == this.modelTypes.W2V2_VITS) { + params.append('emotion', this.settings.dim_emotion); + } + else if (model_type == this.modelTypes.BERT_VITS2) { + params.append('sdp_ratio', this.settings.sdp_ratio); + params.append('emotion', this.settings.emotion); + if (this.settings.text_prompt) { + params.append('text_prompt', this.settings.text_prompt); + } + if (this.settings.style_text) { + params.append('style_text', this.settings.style_text); + params.append('style_weight', this.settings.style_weight); + } + } + + const url = `${this.settings.provider_endpoint}/voice/${model_type.toLowerCase()}`; + + if (streaming) { + return url + `?${params.toString()}`; + } + + const response = await fetch( + url, + { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: params, + }, + ); + if (!response.ok) { + toastr.error(response.statusText, 'TTS Generation Failed'); + throw new Error(`HTTP ${response.status}: ${await response.text()}`); + } + return response; + } + + /** + * Preview TTS for a given voice ID. + * @param {string} id Voice ID + */ + async previewTtsVoice(id) { + this.audioElement.pause(); + this.audioElement.currentTime = 0; + const voice = await this.getVoiceById(id); + const lang = voice.lang.includes(this.settings.lang) ? this.settings.lang : voice.lang[0]; + + let lang_code = this.langKey2LangCode[lang]; + const text = getPreviewString(lang_code); + const response = await this.fetchTtsGeneration(text, id, lang, true); + if (typeof response != 'string') { + if (!response.ok) { + throw new Error(`HTTP ${response.status}: ${await response.text()}`); + } + const audio = await response.blob(); + const url = URL.createObjectURL(audio); + this.audioElement.src = url; + this.audioElement.play(); + } + } + + // Interface not used + async fetchTtsFromHistory(history_item_id) { + return Promise.resolve(history_item_id); + } +} From 2b50ab398b00cbf28ba1c14cf55420156670fcde Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 29 Jun 2024 14:35:16 +0300 Subject: [PATCH 8/8] Add jsconfig exclusions --- jsconfig.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jsconfig.json b/jsconfig.json index e7691789d..a48606f1f 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -15,6 +15,11 @@ "**/node_modules/*", "public/lib", "backups/*", - "data/*" + "data/*", + "**/dist/*", + "dist/*", + "cache/*", + "src/tokenizers/*", + "docker/*", ] }