diff --git a/public/scripts/extensions/connection-manager/index.js b/public/scripts/extensions/connection-manager/index.js index e9d0dd2fe..f31e4b495 100644 --- a/public/scripts/extensions/connection-manager/index.js +++ b/public/scripts/extensions/connection-manager/index.js @@ -30,6 +30,7 @@ const CC_COMMANDS = [ 'api-url', 'model', 'proxy', + 'stop-strings', ]; const TC_COMMANDS = [ @@ -43,6 +44,7 @@ const TC_COMMANDS = [ 'context', 'instruct-state', 'tokenizer', + 'stop-strings', ]; const FANCY_NAMES = { @@ -57,6 +59,7 @@ const FANCY_NAMES = { 'instruct': 'Instruct Template', 'context': 'Context Template', 'tokenizer': 'Tokenizer', + 'stop-strings': 'Custom Stopping Strings', }; /** @@ -138,6 +141,7 @@ const profilesProvider = () => [ * @property {string} [context] Context Template * @property {string} [instruct-state] Instruct Mode * @property {string} [tokenizer] Tokenizer + * @property {string} [stop-strings] Custom Stopping Strings * @property {string[]} [exclude] Commands to exclude */ diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index 2a74f8722..2c1d5cd4c 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -4072,4 +4072,34 @@ $(document).ready(() => { ], helpString: 'activates a movingUI preset by name', })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'stop-strings', + aliases: ['stopping-strings'], + helpString: 'Sets a list of custom stopping strings. Gets the list if no value is provided.', + returns: ARGUMENT_TYPE.LIST, + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'list of strings', + typeList: [ARGUMENT_TYPE.LIST], + acceptsMultiple: false, + isRequired: false, + }), + ], + callback: (_, value) => { + if (String(value ?? '').trim()) { + const parsedValue = ((x) => { try { return JSON.parse(x.toString()); } catch { return null; } })(value); + if (!parsedValue || !Array.isArray(parsedValue)) { + throw new Error('Invalid list format. The value must be a JSON-serialized array of strings.'); + } + parsedValue.forEach((item, index) => { + parsedValue[index] = String(item); + }); + power_user.custom_stopping_strings = JSON.stringify(parsedValue); + $('#custom_stopping_strings').val(power_user.custom_stopping_strings); + saveSettingsDebounced(); + } + + return power_user.custom_stopping_strings; + }, + })); });