Add command and profile for custom stop strings

fad4e4e75e074dd99bca3d5adc63b946b3aa7023

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +34 -0Ignore whitespace
public/scripts/extensions/connection-manager/index.js+4 -0
@@ -30,6 +30,7 @@ const CC_COMMANDS = [
3030 'api-url',
3131 'model',
3232 'proxy',
33+ 'stop-strings',
3334];
3435
3536const TC_COMMANDS = [
@@ -43,6 +44,7 @@ const TC_COMMANDS = [
4344 'context',
4445 'instruct-state',
4546 'tokenizer',
47+ 'stop-strings',
4648];
4749
4850const FANCY_NAMES = {
@@ -57,6 +59,7 @@ const FANCY_NAMES = {
5759 'instruct': 'Instruct Template',
5860 'context': 'Context Template',
5961 'tokenizer': 'Tokenizer',
62+ 'stop-strings': 'Custom Stopping Strings',
6063};
6164
6265/**
@@ -138,6 +141,7 @@ const profilesProvider = () => [
138141 * @property {string} [context] Context Template
139142 * @property {string} [instruct-state] Instruct Mode
140143 * @property {string} [tokenizer] Tokenizer
144+ * @property {string} [stop-strings] Custom Stopping Strings
141145 * @property {string[]} [exclude] Commands to exclude
142146 */
143147
public/scripts/power-user.js+30 -0
@@ -4072,4 +4072,34 @@ $(document).ready(() => {
40724072 ],
40734073 helpString: 'activates a movingUI preset by name',
40744074 }));
4075+ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
4076+ name: 'stop-strings',
4077+ aliases: ['stopping-strings'],
4078+ helpString: 'Sets a list of custom stopping strings. Gets the list if no value is provided.',
4079+ returns: ARGUMENT_TYPE.LIST,
4080+ unnamedArgumentList: [
4081+ SlashCommandArgument.fromProps({
4082+ description: 'list of strings',
4083+ typeList: [ARGUMENT_TYPE.LIST],
4084+ acceptsMultiple: false,
4085+ isRequired: false,
4086+ }),
4087+ ],
4088+ callback: (_, value) => {
4089+ if (String(value ?? '').trim()) {
4090+ const parsedValue = ((x) => { try { return JSON.parse(x.toString()); } catch { return null; } })(value);
4091+ if (!parsedValue || !Array.isArray(parsedValue)) {
4092+ throw new Error('Invalid list format. The value must be a JSON-serialized array of strings.');
4093+ }
4094+ parsedValue.forEach((item, index) => {
4095+ parsedValue[index] = String(item);
4096+ });
4097+ power_user.custom_stopping_strings = JSON.stringify(parsedValue);
4098+ $('#custom_stopping_strings').val(power_user.custom_stopping_strings);
4099+ saveSettingsDebounced();
4100+ }
4101+
4102+ return power_user.custom_stopping_strings;
4103+ },
4104+ }));
40754105});