Add custom stop sequences to instruct mode

This commit is contained in:
SillyLossy
2023-05-10 22:48:14 +03:00
parent 3d49f65b1a
commit 6d102269ac
4 changed files with 70 additions and 24 deletions

View File

@ -1184,33 +1184,15 @@
</div>
</div>
<div>
<h4>Instruct mode</h4>
<h4>Instruct mode
<a href="/notes#instructmode" class="notes-link" target="_blank">
<span class="note-link-span">?</span>
</a>
</h4>
<label for="instruct_enabled" class="checkbox_label">
<input id="instruct_enabled" type="checkbox" />
Enabled
</label>
<label>
System Prompt
</label>
<textarea id="instruct_system_prompt" class="text_pole textarea_compact"></textarea>
<label for="instruct_system_sequence">
System Sequence
</label>
<div>
<input id="instruct_system_sequence" class="text_pole textarea_compact" type="text" maxlength="100" />
</div>
<label for="instruct_input_sequence">
Input Sequence
</label>
<div>
<input id="instruct_input_sequence" class="text_pole textarea_compact" type="text" maxlength="100" />
</div>
<label for="instruct_output_sequence">
Output Sequence
</label>
<div>
<input id="instruct_output_sequence" class="text_pole textarea_compact" type="text" maxlength="100" />
</div>
<label for="instruct_wrap" class="checkbox_label">
<input id="instruct_wrap" type="checkbox" />
Wrap Sequences with Newline
@ -1219,6 +1201,50 @@
<input id="instruct_names" type="checkbox" />
Include Names
</label>
<label for="instruct_presets">Presets</label>
<select id="instruct_presets">
<option>--- UNDER CONSTRUCTION ---</option>
</select>
<label>
System Prompt
</label>
<textarea id="instruct_system_prompt" class="text_pole textarea_compact"></textarea>
<div class="flex-container">
<div class="flex1">
<label for="instruct_input_sequence">
Input Sequence
</label>
<div>
<input id="instruct_input_sequence" class="text_pole textarea_compact" type="text" maxlength="100" />
</div>
</div>
<div class="flex1">
<label for="instruct_output_sequence">
Output Sequence
</label>
<div>
<input id="instruct_output_sequence" class="text_pole textarea_compact" type="text" maxlength="100" />
</div>
</div>
</div>
<div class="flex-container">
<div class="flex1">
<label for="instruct_system_sequence">
System Sequence
</label>
<div>
<input id="instruct_system_sequence" class="text_pole textarea_compact" type="text" maxlength="100" />
</div>
</div>
<div class="flex1">
<label for="instruct_stop_sequence">
Stop Sequence
</label>
<div>
<input id="instruct_stop_sequence" class="text_pole textarea_compact" type="text" maxlength="100" />
</div>
</div>
</div>
</div>
</div>
<div name="ContextFormatting" class="flex1">

View File

@ -414,6 +414,10 @@ Sometimes an AI model may not perceive anchors correctly or the AI model already
_When using Pygmalion models these anchors are automatically disabled, since Pygmalion already generates long enough messages._
## Instruct Mode
_This section is under construction. Please check later._
## Chat import
**Import chats into SillyTavern**

View File

@ -1228,6 +1228,9 @@ function getStoppingStrings(isImpersonate, addSpace) {
}
if (power_user.instruct.enabled) {
// Cohee: This was borrowed from oobabooga's textgen. But..
// What if a model doesn't use newlines to chain sequences?
// Who knows.
if (power_user.instruct.input_sequence) {
result.push(`\n${power_user.instruct.input_sequence}`);
}
@ -1910,7 +1913,13 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
if (i === arrMes.length - 1 && !item.trim().startsWith(name1 + ":")) {
if (textareaText == "") {
item = item.substr(0, item.length - 1);
// Cohee: I think this was added to allow the model to continue
// where it left off by removing the trailing newline at the end
// that was added by chat2 generator. This causes problems with
// instruct mode that could not have a trailing newline. So we're
// removing a newline ONLY at the end of the string if it exists.
item = item.replace(/\n?$/, '');
//item = item.substr(0, item.length - 1);
}
}
if (i === arrMes.length - topAnchorDepth && !is_pygmalion) {
@ -2527,6 +2536,11 @@ function cleanUpMessage(getMessage, isImpersonate) {
getMessage = getMessage.substr(0, getMessage.indexOf('<|endoftext|>'));
}
if (power_user.instruct.enabled && power_user.instruct.stop_sequence) {
if (getMessage.indexOf(power_user.instruct.stop_sequence) != -1) {
getMessage = getMessage.substring(0, getMessage.indexOf(power_user.instruct.stop_sequence));
}
}
// clean-up group message from excessive generations
if (selected_group) {
getMessage = cleanGroupMessage(getMessage);

View File

@ -118,6 +118,7 @@ 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: '',
stop_sequence: '',
input_sequence: '### Instruction:',
output_sequence: '### Response:',
}
@ -537,6 +538,7 @@ function loadInstructMode() {
{ id: "instruct_system_sequence", property: "system_sequence", isCheckbox: false },
{ id: "instruct_input_sequence", property: "input_sequence", isCheckbox: false },
{ id: "instruct_output_sequence", property: "output_sequence", isCheckbox: false },
{ id: "instruct_stop_sequence", property: "stop_sequence", isCheckbox: false },
{ id: "instruct_names", property: "names", isCheckbox: true },
];