mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2024-12-25 00:21:39 +01:00
improved instruct mode sequences (WIP)
This commit is contained in:
parent
f48f7a98fa
commit
be3ebcda0d
@ -2097,14 +2097,14 @@
|
|||||||
<label for="context_story_string">
|
<label for="context_story_string">
|
||||||
<small data-i18n="Story String">Story String</small>
|
<small data-i18n="Story String">Story String</small>
|
||||||
</label>
|
</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="flex-container">
|
||||||
<div class="flex1">
|
<div class="flex1">
|
||||||
<label for="context_example_separator">
|
<label for="context_example_separator">
|
||||||
<small data-i18n="Example Separator">Example Separator</small>
|
<small data-i18n="Example Separator">Example Separator</small>
|
||||||
</label>
|
</label>
|
||||||
<div>
|
<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>
|
</div>
|
||||||
<div class="flex1">
|
<div class="flex1">
|
||||||
@ -2112,7 +2112,7 @@
|
|||||||
<small data-i18n="Chat Start">Chat Start</small>
|
<small data-i18n="Chat Start">Chat Start</small>
|
||||||
</label>
|
</label>
|
||||||
<div>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -2182,7 +2182,7 @@
|
|||||||
<small data-i18n="Input Sequence">Input Sequence</small>
|
<small data-i18n="Input Sequence">Input Sequence</small>
|
||||||
</label>
|
</label>
|
||||||
<div>
|
<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>
|
</div>
|
||||||
<div class="flex1">
|
<div class="flex1">
|
||||||
@ -2190,33 +2190,53 @@
|
|||||||
<small data-i18n="Output Sequence">Output Sequence</small>
|
<small data-i18n="Output Sequence">Output Sequence</small>
|
||||||
</label>
|
</label>
|
||||||
<div>
|
<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>
|
</div>
|
||||||
<div class="flex1">
|
<div class="flex1">
|
||||||
<label for="instruct_last_output_sequence">
|
<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>
|
</label>
|
||||||
<div>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-container">
|
<div class="flex-container">
|
||||||
<div class="flex1">
|
<div class="flex1">
|
||||||
<label for="instruct_system_sequence">
|
<label for="instruct_system_sequence">
|
||||||
<small data-i18n="System Sequence">System Sequence</small>
|
<small data-i18n="System Sequence Prefix">System Sequence Prefix</small>
|
||||||
</label>
|
</label>
|
||||||
<div>
|
<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>
|
</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">
|
<div class="flex1">
|
||||||
<label for="instruct_stop_sequence">
|
<label for="instruct_stop_sequence">
|
||||||
<small data-i18n="Stop Sequence">Stop Sequence</small>
|
<small data-i18n="Stop Sequence">Stop Sequence</small>
|
||||||
</label>
|
</label>
|
||||||
<div>
|
<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>
|
</div>
|
||||||
<div class="flex1">
|
<div class="flex1">
|
||||||
@ -2224,7 +2244,7 @@
|
|||||||
<small data-i18n="Separator">Separator</small>
|
<small data-i18n="Separator">Separator</small>
|
||||||
</label>
|
</label>
|
||||||
<div>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -3,8 +3,10 @@
|
|||||||
"system_prompt": "Write {{char}}'s next reply in this fictional roleplay with {{user}}.",
|
"system_prompt": "Write {{char}}'s next reply in this fictional roleplay with {{user}}.",
|
||||||
"input_sequence": "[INST] ",
|
"input_sequence": "[INST] ",
|
||||||
"output_sequence": " [/INST] ",
|
"output_sequence": " [/INST] ",
|
||||||
|
"first_output_sequence": "[/INST] ",
|
||||||
"last_output_sequence": "",
|
"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": "",
|
"stop_sequence": "",
|
||||||
"separator_sequence": "\n",
|
"separator_sequence": "\n",
|
||||||
"wrap": false,
|
"wrap": false,
|
||||||
|
@ -2431,6 +2431,11 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
|
|
||||||
chat2[i] = formatMessageHistoryItem(coreChat[j], isInstruct, false);
|
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
|
// Do not suffix the message for continuation
|
||||||
if (i === 0 && isContinue) {
|
if (i === 0 && isContinue) {
|
||||||
if (isInstruct) {
|
if (isInstruct) {
|
||||||
|
@ -17,6 +17,7 @@ const controls = [
|
|||||||
{ id: "instruct_wrap", property: "wrap", isCheckbox: true },
|
{ id: "instruct_wrap", property: "wrap", isCheckbox: true },
|
||||||
{ id: "instruct_system_prompt", property: "system_prompt", isCheckbox: false },
|
{ id: "instruct_system_prompt", property: "system_prompt", isCheckbox: false },
|
||||||
{ id: "instruct_system_sequence", property: "system_sequence", 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_separator_sequence", property: "separator_sequence", isCheckbox: false },
|
||||||
{ id: "instruct_input_sequence", property: "input_sequence", isCheckbox: false },
|
{ id: "instruct_input_sequence", property: "input_sequence", isCheckbox: false },
|
||||||
{ id: "instruct_output_sequence", property: "output_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_names", property: "names", isCheckbox: true },
|
||||||
{ id: "instruct_macro", property: "macro", isCheckbox: true },
|
{ id: "instruct_macro", property: "macro", isCheckbox: true },
|
||||||
{ id: "instruct_names_force_groups", property: "names_force_groups", 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_last_output_sequence", property: "last_output_sequence", isCheckbox: false },
|
||||||
{ id: "instruct_activation_regex", property: "activation_regex", isCheckbox: false },
|
{ id: "instruct_activation_regex", property: "activation_regex", isCheckbox: false },
|
||||||
];
|
];
|
||||||
@ -200,9 +202,10 @@ export function getInstructStoppingSequences() {
|
|||||||
if (power_user.instruct.enabled) {
|
if (power_user.instruct.enabled) {
|
||||||
const input_sequence = power_user.instruct.input_sequence;
|
const input_sequence = power_user.instruct.input_sequence;
|
||||||
const output_sequence = power_user.instruct.output_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 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);
|
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;
|
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) {
|
if (forceLastOutputSequence) {
|
||||||
sequence = power_user.instruct.last_output_sequence;
|
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) {
|
if (power_user.instruct.macro) {
|
||||||
@ -254,14 +261,14 @@ export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvata
|
|||||||
* @returns {string} Formatted instruct mode system prompt.
|
* @returns {string} Formatted instruct mode system prompt.
|
||||||
*/
|
*/
|
||||||
export function formatInstructModeSystemPrompt(systemPrompt){
|
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}}")) {
|
if (power_user.instruct.system_sequence) {
|
||||||
return power_user.instruct.system_sequence.replace(/{{sys}}/gi, systemPrompt);
|
systemPrompt = power_user.instruct.system_sequence + separator + systemPrompt;
|
||||||
} else {
|
}
|
||||||
return 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;
|
return systemPrompt;
|
||||||
|
@ -163,9 +163,11 @@ let power_user = {
|
|||||||
names: false,
|
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_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: '',
|
||||||
|
system_sequence_suffix: '',
|
||||||
stop_sequence: '',
|
stop_sequence: '',
|
||||||
input_sequence: '### Instruction:',
|
input_sequence: '### Instruction:',
|
||||||
output_sequence: '### Response:',
|
output_sequence: '### Response:',
|
||||||
|
first_output_sequence: '',
|
||||||
last_output_sequence: '',
|
last_output_sequence: '',
|
||||||
preset: 'Alpaca',
|
preset: 'Alpaca',
|
||||||
separator_sequence: '',
|
separator_sequence: '',
|
||||||
|
Loading…
Reference in New Issue
Block a user