diff --git a/public/scripts/extensions/connection-manager/index.js b/public/scripts/extensions/connection-manager/index.js index fbcf69c7f..34c79205a 100644 --- a/public/scripts/extensions/connection-manager/index.js +++ b/public/scripts/extensions/connection-manager/index.js @@ -40,6 +40,7 @@ const CC_COMMANDS = [ 'stop-strings', 'start-reply-with', 'reasoning-template', + 'prompt-post-processing', ]; const TC_COMMANDS = [ @@ -73,6 +74,7 @@ const FANCY_NAMES = { 'stop-strings': 'Custom Stopping Strings', 'start-reply-with': 'Start Reply With', 'reasoning-template': 'Reasoning Template', + 'prompt-post-processing': 'Prompt Post-Processing', }; /** diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 58c4d8cad..eb11d5708 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -33,6 +33,7 @@ import { removeMacros, renameCharacter, saveChatConditional, + saveSettingsDebounced, sendMessageAsUser, sendSystemMessage, setActiveCharacter, @@ -2363,6 +2364,56 @@ export function initDefaultSlashCommands() { helpString: 'Copies the provided text to the OS clipboard. Returns an empty string.', })); + + const promptPostProcessingEnumProvider = () => Array + .from(document.getElementById('custom_prompt_post_processing').querySelectorAll('option')) + .map(option => new SlashCommandEnumValue(option.value || 'none', option.textContent, enumTypes.enum)); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'prompt-post-processing', + aliases: ['ppp'], + helpString: ` +
+ Sets a "Prompt Post-Processing" type. Gets the current selection if no value is provided. +
+
+ Examples: +
+ + `, + namedArgumentList: [], + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'value', + typeList: [ARGUMENT_TYPE.STRING], + acceptsMultiple: false, + isRequired: true, + forceEnum: true, + enumProvider: promptPostProcessingEnumProvider, + }), + ], + callback: (_args, value) => { + const stringValue = String(value ?? '').trim().toLowerCase(); + if (!stringValue) { + return oai_settings.custom_prompt_post_processing || 'none'; + } + + const validValues = promptPostProcessingEnumProvider().map(option => option.value); + if (!validValues.includes(stringValue)) { + throw new Error(`Invalid value "${stringValue}". Valid values are: ${validValues.join(', ')}`); + } + + // 'none' value must be coerced to an empty string + oai_settings.custom_prompt_post_processing = stringValue === 'none' ? '' : stringValue; + $('#custom_prompt_post_processing').val(oai_settings.custom_prompt_post_processing); + saveSettingsDebounced(); + + return oai_settings.custom_prompt_post_processing; + }, + })); + registerVariableCommands(); }