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 @@
3885 <input id="instruct_macro" type="checkbox" />3885 <input id="instruct_macro" type="checkbox" />
3886 <small data-i18n="Replace Macro in Sequences">Replace Macro in Sequences</small>3886 <small data-i18n="Replace Macro in Sequences">Replace Macro in Sequences</small>
3887 </label>3887 </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>
3888 <label for="instruct_skip_examples" class="checkbox_label">3892 <label for="instruct_skip_examples" class="checkbox_label">
3889 <input id="instruct_skip_examples" type="checkbox" />3893 <input id="instruct_skip_examples" type="checkbox" />
3890 <small data-i18n="Skip Example Dialogues Formatting">Skip Example Dialogues Formatting</small>3894 <small data-i18n="Skip Example Dialogues Formatting">Skip Example Dialogues Formatting</small>
public/scripts/instruct-mode.js+10 -3
@@ -7,7 +7,7 @@ import {
7 power_user,7 power_user,
8 context_presets,8 context_presets,
9} from './power-user.js';9} from './power-user.js';
10import { regexFromString, resetScrollHeight } from './utils.js';10import { onlyUnique, regexFromString, resetScrollHeight } from './utils.js';
1111
12/**12/**
13 * @type {any[]} Instruct mode presets.13 * @type {any[]} Instruct mode presets.
@@ -44,6 +44,7 @@ const controls = [
44 { id: 'instruct_skip_examples', property: 'skip_examples', isCheckbox: true },44 { id: 'instruct_skip_examples', property: 'skip_examples', isCheckbox: true },
45 { id: 'instruct_names_behavior', property: 'names_behavior', isCheckbox: false },45 { id: 'instruct_names_behavior', property: 'names_behavior', isCheckbox: false },
46 { id: 'instruct_system_same_as_user', property: 'system_same_as_user', isCheckbox: true, trigger: true },46 { 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 },
47];48];
4849
49/**50/**
@@ -79,6 +80,7 @@ function migrateInstructModeSettings(settings) {
79 skip_examples: false,80 skip_examples: false,
80 system_same_as_user: false,81 system_same_as_user: false,
81 names_behavior: names_behavior_types.FORCE,82 names_behavior: names_behavior_types.FORCE,
83 sequences_as_stop_strings: true,
82 };84 };
8385
84 for (let key in defaults) {86 for (let key in defaults) {
@@ -321,15 +323,20 @@ export function getInstructStoppingSequences({ customInstruct = null, useStopStr
321323
322 const combined_sequence = [324 const combined_sequence = [
323 stop_sequence,325 stop_sequence,
326 ];
327
328 if (instruct.sequences_as_stop_strings) {
329 combined_sequence.push(
324 input_sequence,330 input_sequence,
325 output_sequence,331 output_sequence,
326 first_output_sequence,332 first_output_sequence,
327 last_output_sequence,333 last_output_sequence,
328 system_sequence,334 system_sequence,
329 last_system_sequence,335 last_system_sequence,
330 ].join('\n');336 );
337 }
331338
332 combined_sequence.split('\n').filter((line, index, self) => self.indexOf(line) === index).forEach(addInstructSequence);339 combined_sequence.join('\n').split('\n').filter(onlyUnique).forEach(addInstructSequence);
333 }340 }
334341
335 if (useStopStrings ?? power_user.context.use_stop_strings) {342 if (useStopStrings ?? power_user.context.use_stop_strings) {
public/scripts/power-user.js+1 -0
@@ -239,6 +239,7 @@ export const power_user = {
239 system_same_as_user: false,239 system_same_as_user: false,
240 /** @deprecated Use output_suffix instead */240 /** @deprecated Use output_suffix instead */
241 separator_sequence: '',241 separator_sequence: '',
242 sequences_as_stop_strings: true,
242 },243 },
243244
244 context: {245 context: {