mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-09 08:38:53 +01:00
Add instruct mode sequence macros
This commit is contained in:
parent
3bc91f10ec
commit
fb08552d46
@ -186,6 +186,7 @@ import {
|
||||
getInstructStoppingSequences,
|
||||
autoSelectInstructPreset,
|
||||
formatInstructModeSystemPrompt,
|
||||
replaceInstructMacros,
|
||||
} from "./scripts/instruct-mode.js";
|
||||
import { applyLocale } from "./scripts/i18n.js";
|
||||
import { getFriendlyTokenizerName, getTokenCount, getTokenizerModel, initTokenizers, saveTokenCache } from "./scripts/tokenizers.js";
|
||||
@ -2013,6 +2014,7 @@ function substituteParams(content, _name1, _name2, _original, _group, _replaceCh
|
||||
}
|
||||
content = diceRollReplace(content);
|
||||
content = randomReplace(content);
|
||||
content = replaceInstructMacros(content);
|
||||
content = replaceVariableMacros(content);
|
||||
content = content.replace(/{{newline}}/gi, "\n");
|
||||
content = content.replace(/{{input}}/gi, String($('#send_textarea').val()));
|
||||
|
@ -358,6 +358,31 @@ function selectMatchingContextTemplate(name) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces instruct mode macros in the given input string.
|
||||
* @param {string} input Input string.
|
||||
* @returns {string} String with macros replaced.
|
||||
*/
|
||||
export function replaceInstructMacros(input) {
|
||||
if (!input) {
|
||||
return '';
|
||||
}
|
||||
|
||||
input = input.replace(/{{instructSystem}}/gi, power_user.instruct.enabled ? power_user.instruct.system_prompt : '');
|
||||
input = input.replace(/{{instructSystemPrefix}}/gi, power_user.instruct.enabled ? power_user.instruct.system_sequence_prefix : '');
|
||||
input = input.replace(/{{instructSystemSuffix}}/gi, power_user.instruct.enabled ? power_user.instruct.system_sequence_suffix : '');
|
||||
input = input.replace(/{{instructInput}}/gi, power_user.instruct.enabled ? power_user.instruct.input_sequence : '');
|
||||
input = input.replace(/{{instructOutput}}/gi, power_user.instruct.enabled ? power_user.instruct.output_sequence : '');
|
||||
input = input.replace(/{{instructFirstOutput}}/gi, power_user.instruct.enabled ? (power_user.instruct.first_output_sequence || power_user.instruct.output_sequence) : '');
|
||||
input = input.replace(/{{instructLastOutput}}/gi, power_user.instruct.enabled ? (power_user.instruct.last_output_sequence || power_user.instruct.output_sequence) : '');
|
||||
input = input.replace(/{{instructSeparator}}/gi, power_user.instruct.enabled ? power_user.instruct.separator_sequence : '');
|
||||
input = input.replace(/{{instructStop}}/gi, power_user.instruct.enabled ? power_user.instruct.stop_sequence : '');
|
||||
input = input.replace(/{{exampleSeparator}}/gi, power_user.context.example_separator);
|
||||
input = input.replace(/{{chatStart}}/gi, power_user.context.chat_start);
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
jQuery(() => {
|
||||
$('#instruct_set_default').on('click', function () {
|
||||
if (power_user.instruct.preset === power_user.default_instruct) {
|
||||
|
@ -32,6 +32,25 @@
|
||||
<li><tt>{{random::(arg1)::(arg2)}}</tt> – alternative syntax for random that allows to use commas in the list items.</li>
|
||||
<li><tt>{{banned "text here"}}</tt> – dynamically add text in the quotes to banned words sequences, if Text Generation WebUI backend used. Do nothing for others backends. Can be used anywhere (Character description, WI, AN, etc.) Quotes around the text are important.</li>
|
||||
</ul>
|
||||
<div>
|
||||
Instruct Mode and Context Template Macros:
|
||||
</div>
|
||||
<div>
|
||||
<small>(enabled in the Advanced Formatting settings)</small>
|
||||
</div>
|
||||
<ul>
|
||||
<li><tt>{{exampleSeparator}}</tt> – context template example dialogues separator</li>
|
||||
<li><tt>{{chatStart}}</tt> – context template chat start line</li>
|
||||
<li><tt>{{instructSystem}}</tt> – instruct system prompt</li>
|
||||
<li><tt>{{instructSystemPrefix}}</tt> – instruct system prompt prefix sequence</li>
|
||||
<li><tt>{{instructSystemSuffix}}</tt> – instruct system prompt suffix sequence</li>
|
||||
<li><tt>{{instructInput}}</tt> – instruct user input sequence</li>
|
||||
<li><tt>{{instructOutput}}</tt> – instruct assistant output sequence</li>
|
||||
<li><tt>{{instructFirstOutput}}</tt> – instruct assistant first output sequence</li>
|
||||
<li><tt>{{instructLastOutput}}</tt> – instruct assistant last output sequence</li>
|
||||
<li><tt>{{instructSeparator}}</tt> – instruct turn separator sequence</li>
|
||||
<li><tt>{{instructStop}}</tt> – instruct stop sequence</li>
|
||||
</ul>
|
||||
<div>
|
||||
Chat variables Macros:
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user