improved instruct mode sequences (WIP)

This commit is contained in:
Stefan Daniel Schwarz 2023-08-25 14:01:25 +02:00
parent f48f7a98fa
commit be3ebcda0d
5 changed files with 58 additions and 22 deletions

View File

@ -2097,14 +2097,14 @@
<label for="context_story_string">
<small data-i18n="Story String">Story String</small>
</label>
<textarea id="context_story_string" class="text_pole textarea_compact" rows="6"></textarea>
<textarea id="context_story_string" class="text_pole textarea_compact" rows="3"></textarea>
<div class="flex-container">
<div class="flex1">
<label for="context_example_separator">
<small data-i18n="Example Separator">Example Separator</small>
</label>
<div>
<textarea id="context_example_separator" class="text_pole textarea_compact" maxlength="500" rows="2"></textarea>
<textarea id="context_example_separator" class="text_pole textarea_compact" maxlength="500" rows="1"></textarea>
</div>
</div>
<div class="flex1">
@ -2112,7 +2112,7 @@
<small data-i18n="Chat Start">Chat Start</small>
</label>
<div>
<textarea id="context_chat_start" class="text_pole textarea_compact" maxlength="500" rows="2"></textarea>
<textarea id="context_chat_start" class="text_pole textarea_compact" maxlength="500" rows="1"></textarea>
</div>
</div>
</div>
@ -2182,7 +2182,7 @@
<small data-i18n="Input Sequence">Input Sequence</small>
</label>
<div>
<textarea id="instruct_input_sequence" class="text_pole textarea_compact" maxlength="500" rows="2"></textarea>
<textarea id="instruct_input_sequence" class="text_pole textarea_compact" maxlength="500" rows="1"></textarea>
</div>
</div>
<div class="flex1">
@ -2190,33 +2190,53 @@
<small data-i18n="Output Sequence">Output Sequence</small>
</label>
<div>
<textarea id="instruct_output_sequence" class="text_pole wide100p textarea_compact" maxlength="500" rows="2"></textarea>
<textarea id="instruct_output_sequence" class="text_pole wide100p textarea_compact" maxlength="500" rows="1"></textarea>
</div>
</div>
</div>
<div class="flex-container">
<div class="flex1">
<label for="instruct_first_output_sequence">
<small data-i18n="First Output Sequence">First Output Sequence</small>
</label>
<div>
<textarea id="instruct_first_output_sequence" class="text_pole textarea_compact" maxlength="500" rows="1"></textarea>
</div>
</div>
<div class="flex1">
<label for="instruct_last_output_sequence">
<small data-i18n="Last Sequence">Last Sequence</small>
<small data-i18n="Last Output Sequence">Last Output Sequence</small>
</label>
<div>
<textarea id="instruct_last_output_sequence" class="text_pole wide100p textarea_compact" maxlength="500" rows="2"></textarea>
<textarea id="instruct_last_output_sequence" class="text_pole wide100p textarea_compact" maxlength="500" rows="1"></textarea>
</div>
</div>
</div>
<div class="flex-container">
<div class="flex1">
<label for="instruct_system_sequence">
<small data-i18n="System Sequence">System Sequence</small>
<small data-i18n="System Sequence Prefix">System Sequence Prefix</small>
</label>
<div>
<textarea id="instruct_system_sequence" class="text_pole textarea_compact" maxlength="500" rows="2"></textarea>
<textarea id="instruct_system_sequence" class="text_pole textarea_compact" maxlength="500" rows="1"></textarea>
</div>
</div>
<div class="flex1">
<label for="instruct_system_sequence_suffix">
<small data-i18n="System Sequence Suffix">System Sequence Suffix</small>
</label>
<div>
<textarea id="instruct_system_sequence_suffix" class="text_pole wide100p textarea_compact" maxlength="500" rows="1"></textarea>
</div>
</div>
</div>
<div class="flex-container">
<div class="flex1">
<label for="instruct_stop_sequence">
<small data-i18n="Stop Sequence">Stop Sequence</small>
</label>
<div>
<textarea id="instruct_stop_sequence" class="text_pole wide100p textarea_compact" maxlength="500" rows="2"></textarea>
<textarea id="instruct_stop_sequence" class="text_pole textarea_compact" maxlength="500" rows="1"></textarea>
</div>
</div>
<div class="flex1">
@ -2224,7 +2244,7 @@
<small data-i18n="Separator">Separator</small>
</label>
<div>
<textarea id="instruct_separator_sequence" class="text_pole wide100p textarea_compact" maxlength="500" rows="2"></textarea>
<textarea id="instruct_separator_sequence" class="text_pole wide100p textarea_compact" maxlength="500" rows="1"></textarea>
</div>
</div>
</div>

View File

@ -3,8 +3,10 @@
"system_prompt": "Write {{char}}'s next reply in this fictional roleplay with {{user}}.",
"input_sequence": "[INST] ",
"output_sequence": " [/INST] ",
"first_output_sequence": "[/INST] ",
"last_output_sequence": "",
"system_sequence": "[INST] <<SYS>>\n{{sys}}\n<</SYS>>\n",
"system_sequence": "[INST] <<SYS>>\n",
"system_sequence_suffix": "\n<</SYS>>\n",
"stop_sequence": "",
"separator_sequence": "\n",
"wrap": false,

View File

@ -2431,6 +2431,11 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, false);
if (j === 0 && isInstruct) {
// Reformat with the first output line (if any)
chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, true);
}
// Do not suffix the message for continuation
if (i === 0 && isContinue) {
if (isInstruct) {

View File

@ -17,6 +17,7 @@ const controls = [
{ id: "instruct_wrap", property: "wrap", isCheckbox: true },
{ id: "instruct_system_prompt", property: "system_prompt", isCheckbox: false },
{ id: "instruct_system_sequence", property: "system_sequence", isCheckbox: false },
{ id: "instruct_system_sequence_suffix", property: "system_sequence_suffix", isCheckbox: false },
{ id: "instruct_separator_sequence", property: "separator_sequence", isCheckbox: false },
{ id: "instruct_input_sequence", property: "input_sequence", isCheckbox: false },
{ id: "instruct_output_sequence", property: "output_sequence", isCheckbox: false },
@ -24,6 +25,7 @@ const controls = [
{ id: "instruct_names", property: "names", isCheckbox: true },
{ id: "instruct_macro", property: "macro", isCheckbox: true },
{ id: "instruct_names_force_groups", property: "names_force_groups", isCheckbox: true },
{ id: "instruct_first_output_sequence", property: "first_output_sequence", isCheckbox: false },
{ id: "instruct_last_output_sequence", property: "last_output_sequence", isCheckbox: false },
{ id: "instruct_activation_regex", property: "activation_regex", isCheckbox: false },
];
@ -200,9 +202,10 @@ export function getInstructStoppingSequences() {
if (power_user.instruct.enabled) {
const input_sequence = power_user.instruct.input_sequence;
const output_sequence = power_user.instruct.output_sequence;
const first_output_sequence = power_user.instruct.first_output_sequence;
const last_output_sequence = power_user.instruct.last_output_sequence;
const combined_sequence = `${input_sequence}\n${output_sequence}\n${last_output_sequence}`;
const combined_sequence = `${input_sequence}\n${output_sequence}\n${first_output_sequence}\n${last_output_sequence}`;
combined_sequence.split('\n').filter((line, index, self) => self.indexOf(line) === index).forEach(addInstructSequence);
}
@ -231,8 +234,12 @@ export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvata
let sequence = (isUser || isNarrator) ? power_user.instruct.input_sequence : power_user.instruct.output_sequence;
if (sequence === power_user.instruct.output_sequence && forceLastOutputSequence && power_user.instruct.last_output_sequence) {
sequence = power_user.instruct.last_output_sequence;
if (forceLastOutputSequence) {
if (sequence === power_user.instruct.output_sequence && power_user.instruct.first_output_sequence) {
sequence = power_user.instruct.first_output_sequence;
} else if (sequence === power_user.instruct.output_sequence && power_user.instruct.last_output_sequence) {
sequence = power_user.instruct.last_output_sequence;
}
}
if (power_user.instruct.macro) {
@ -254,14 +261,14 @@ export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvata
* @returns {string} Formatted instruct mode system prompt.
*/
export function formatInstructModeSystemPrompt(systemPrompt){
if (power_user.instruct.system_sequence) {
const separator = power_user.instruct.wrap ? '\n' : '';
const separator = power_user.instruct.wrap ? '\n' : '';
if (power_user.instruct.system_sequence.includes("{{sys}}")) {
return power_user.instruct.system_sequence.replace(/{{sys}}/gi, systemPrompt);
} else {
return power_user.instruct.system_sequence + separator + systemPrompt;
}
if (power_user.instruct.system_sequence) {
systemPrompt = power_user.instruct.system_sequence + separator + systemPrompt;
}
if (power_user.instruct.system_sequence_suffix) {
systemPrompt = systemPrompt + separator + power_user.instruct.system_sequence_suffix;
}
return systemPrompt;

View File

@ -163,9 +163,11 @@ let power_user = {
names: false,
system_prompt: "Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\nWrite {{char}}'s next reply in a fictional roleplay chat between {{user}} and {{char}}. Write 1 reply only.",
system_sequence: '',
system_sequence_suffix: '',
stop_sequence: '',
input_sequence: '### Instruction:',
output_sequence: '### Response:',
first_output_sequence: '',
last_output_sequence: '',
preset: 'Alpaca',
separator_sequence: '',