Instruct: Add Sequences as Stop Strings control (#4355) * Instruct: Add Sequences as Stop Strings control * lint fix
Signed| @@ -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> |
| @@ -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'; |
| 10 | import { regexFromString, resetScrollHeight } from './utils.js'; | 10 | import { onlyUnique, regexFromString, resetScrollHeight } from './utils.js'; |
| 11 | 11 | ||
| 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 | ]; |
| 48 | 49 | ||
| 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 | }; |
| 83 | 85 | ||
| 84 | for (let key in defaults) { | 86 | for (let key in defaults) { |
| @@ -321,15 +323,20 @@ export function getInstructStoppingSequences({ customInstruct = null, useStopStr | |||
| 321 | 323 | ||
| 322 | const combined_sequence = [ | 324 | const combined_sequence = [ |
| 323 | stop_sequence, | 325 | stop_sequence, |
| 324 | input_sequence, | 326 | ]; |
| 325 | output_sequence, | 327 | |
| 326 | first_output_sequence, | 328 | if (instruct.sequences_as_stop_strings) { |
| 327 | last_output_sequence, | 329 | combined_sequence.push( |
| 328 | system_sequence, | 330 | input_sequence, |
| 329 | last_system_sequence, | 331 | output_sequence, |
| 330 | ].join('\n'); | 332 | first_output_sequence, |
| 331 | 333 | last_output_sequence, | |
| 332 | combined_sequence.split('\n').filter((line, index, self) => self.indexOf(line) === index).forEach(addInstructSequence); | 334 | system_sequence, |
| 335 | last_system_sequence, | ||
| 336 | ); | ||
| 337 | } | ||
| 338 | |||
| 339 | combined_sequence.join('\n').split('\n').filter(onlyUnique).forEach(addInstructSequence); | ||
| 333 | } | 340 | } |
| 334 | 341 | ||
| 335 | if (useStopStrings ?? power_user.context.use_stop_strings) { | 342 | if (useStopStrings ?? power_user.context.use_stop_strings) { |
| @@ -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 | }, |
| 243 | 244 | ||
| 244 | context: { | 245 | context: { |