Add command and profile for custom stop strings
| @@ -30,6 +30,7 @@ const CC_COMMANDS = [ | |||
| 30 | 'api-url', | 30 | 'api-url', |
| 31 | 'model', | 31 | 'model', |
| 32 | 'proxy', | 32 | 'proxy', |
| 33 | 'stop-strings', | ||
| 33 | ]; | 34 | ]; |
| 34 | 35 | ||
| 35 | const TC_COMMANDS = [ | 36 | const TC_COMMANDS = [ |
| @@ -43,6 +44,7 @@ const TC_COMMANDS = [ | |||
| 43 | 'context', | 44 | 'context', |
| 44 | 'instruct-state', | 45 | 'instruct-state', |
| 45 | 'tokenizer', | 46 | 'tokenizer', |
| 47 | 'stop-strings', | ||
| 46 | ]; | 48 | ]; |
| 47 | 49 | ||
| 48 | const FANCY_NAMES = { | 50 | const FANCY_NAMES = { |
| @@ -57,6 +59,7 @@ const FANCY_NAMES = { | |||
| 57 | 'instruct': 'Instruct Template', | 59 | 'instruct': 'Instruct Template', |
| 58 | 'context': 'Context Template', | 60 | 'context': 'Context Template', |
| 59 | 'tokenizer': 'Tokenizer', | 61 | 'tokenizer': 'Tokenizer', |
| 62 | 'stop-strings': 'Custom Stopping Strings', | ||
| 60 | }; | 63 | }; |
| 61 | 64 | ||
| 62 | /** | 65 | /** |
| @@ -138,6 +141,7 @@ const profilesProvider = () => [ | |||
| 138 | * @property {string} [context] Context Template | 141 | * @property {string} [context] Context Template |
| 139 | * @property {string} [instruct-state] Instruct Mode | 142 | * @property {string} [instruct-state] Instruct Mode |
| 140 | * @property {string} [tokenizer] Tokenizer | 143 | * @property {string} [tokenizer] Tokenizer |
| 144 | * @property {string} [stop-strings] Custom Stopping Strings | ||
| 141 | * @property {string[]} [exclude] Commands to exclude | 145 | * @property {string[]} [exclude] Commands to exclude |
| 142 | */ | 146 | */ |
| 143 | 147 | ||
| @@ -4072,4 +4072,34 @@ $(document).ready(() => { | |||
| 4072 | ], | 4072 | ], |
| 4073 | helpString: 'activates a movingUI preset by name', | 4073 | helpString: 'activates a movingUI preset by name', |
| 4074 | })); | 4074 | })); |
| 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 | })); | ||
| 4075 | }); | 4105 | }); |