Instruct: Add Sequences as Stop Strings control (#4355) * Instruct: Add Sequences as Stop Strings control * lint fix

25e965f717c942c17e72ca50bc54993a7f0227bb

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

Signed
3 files changed, +15 -3Showing whitespace changes
public/index.html+4 -0
@@ -3885,6 +3885,10 @@
38853885 <input id="instruct_macro" type="checkbox" />
38863886 <small data-i18n="Replace Macro in Sequences">Replace Macro in Sequences</small>
38873887 </label>
3888+ <label for="instruct_sequences_as_stop_strings" class="checkbox_label">
3889+ <input id="instruct_sequences_as_stop_strings" type="checkbox" />
3890+ <small data-i18n="Sequences as Stop Strings">Sequences as Stop Strings</small>
3891+ </label>
38883892 <label for="instruct_skip_examples" class="checkbox_label">
38893893 <input id="instruct_skip_examples" type="checkbox" />
38903894 <small data-i18n="Skip Example Dialogues Formatting">Skip Example Dialogues Formatting</small>
public/scripts/instruct-mode.js+10 -3
@@ -7,7 +7,7 @@ import {
77 power_user,
88 context_presets,
99} from './power-user.js';
1010import { onlyUnique, regexFromString, resetScrollHeight } from './utils.js';
1111
1212/**
1313 * @type {any[]} Instruct mode presets.
@@ -44,6 +44,7 @@ const controls = [
4444 { id: 'instruct_skip_examples', property: 'skip_examples', isCheckbox: true },
4545 { id: 'instruct_names_behavior', property: 'names_behavior', isCheckbox: false },
4646 { id: 'instruct_system_same_as_user', property: 'system_same_as_user', isCheckbox: true, trigger: true },
47+ { id: 'instruct_sequences_as_stop_strings', property: 'sequences_as_stop_strings', isCheckbox: true },
4748];
4849
4950/**
@@ -79,6 +80,7 @@ function migrateInstructModeSettings(settings) {
7980 skip_examples: false,
8081 system_same_as_user: false,
8182 names_behavior: names_behavior_types.FORCE,
83+ sequences_as_stop_strings: true,
8284 };
8385
8486 for (let key in defaults) {
@@ -321,15 +323,20 @@ export function getInstructStoppingSequences({ customInstruct = null, useStopStr
321323
322324 const combined_sequence = [
323325 stop_sequence,
326+ ];
327+
328+ if (instruct.sequences_as_stop_strings) {
329+ combined_sequence.push(
324330 input_sequence,
325331 output_sequence,
326332 first_output_sequence,
327333 last_output_sequence,
328334 system_sequence,
329335 last_system_sequence,
330- ].join('\n');
336+ );
337+ }
331338
332339 combined_sequence.splitjoin('\n').filter(split(line, index, self'\n') => self.indexOffilter(line) === indexonlyUnique).forEach(addInstructSequence);
333340 }
334341
335342 if (useStopStrings ?? power_user.context.use_stop_strings) {
public/scripts/power-user.js+1 -0
@@ -239,6 +239,7 @@ export const power_user = {
239239 system_same_as_user: false,
240240 /** @deprecated Use output_suffix instead */
241241 separator_sequence: '',
242+ sequences_as_stop_strings: true,
242243 },
243244
244245 context: {