mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Format instruct mode examples
This commit is contained in:
@@ -66,6 +66,7 @@ import {
|
|||||||
pygmalion_options,
|
pygmalion_options,
|
||||||
tokenizers,
|
tokenizers,
|
||||||
formatInstructModeChat,
|
formatInstructModeChat,
|
||||||
|
formatInstructModeExamples,
|
||||||
formatInstructModePrompt,
|
formatInstructModePrompt,
|
||||||
persona_description_positions,
|
persona_description_positions,
|
||||||
loadMovingUIState,
|
loadMovingUIState,
|
||||||
@@ -2542,6 +2543,9 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
if (mesExamples.replace(/<START>/gi, '').trim().length === 0) {
|
if (mesExamples.replace(/<START>/gi, '').trim().length === 0) {
|
||||||
mesExamples = '';
|
mesExamples = '';
|
||||||
}
|
}
|
||||||
|
if (mesExamples && isInstruct) {
|
||||||
|
mesExamples = formatInstructModeExamples(mesExamples, name1, name2)
|
||||||
|
}
|
||||||
|
|
||||||
const exampleSeparator = power_user.context.example_separator ? `${power_user.context.example_separator}\n` : '';
|
const exampleSeparator = power_user.context.example_separator ? `${power_user.context.example_separator}\n` : '';
|
||||||
const blockHeading = main_api === 'openai' ? '<START>\n' : exampleSeparator;
|
const blockHeading = main_api === 'openai' ? '<START>\n' : exampleSeparator;
|
||||||
|
@@ -1088,6 +1088,26 @@ export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvata
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatInstructModeExamples(mesExamples, name1, name2) {
|
||||||
|
const includeNames = power_user.instruct.names || (!!selected_group && power_user.instruct.names_force_groups);
|
||||||
|
|
||||||
|
let inputSequence = power_user.instruct.input_sequence;
|
||||||
|
let outputSequence = power_user.instruct.output_sequence;
|
||||||
|
|
||||||
|
if (power_user.instruct.macro) {
|
||||||
|
inputSequence = substituteParams(inputSequence, name1, name2);
|
||||||
|
outputSequence = substituteParams(outputSequence, name1, name2);
|
||||||
|
}
|
||||||
|
|
||||||
|
const separator = power_user.instruct.wrap ? '\n' : '';
|
||||||
|
const separatorSequence = power_user.instruct.separator_sequence ? power_user.instruct.separator_sequence : separator;
|
||||||
|
|
||||||
|
mesExamples = mesExamples.replace(new RegExp(`\n${name1}: `, "gm"), separatorSequence + inputSequence + separator + (includeNames ? `${name1}: ` : ''));
|
||||||
|
mesExamples = mesExamples.replace(new RegExp(`\n${name2}: `, "gm"), separator + outputSequence + separator + (includeNames ? `${name2}: ` : ''));
|
||||||
|
|
||||||
|
return mesExamples;
|
||||||
|
}
|
||||||
|
|
||||||
export function formatInstructModePrompt(name, isImpersonate, promptBias, name1, name2) {
|
export function formatInstructModePrompt(name, isImpersonate, promptBias, name1, name2) {
|
||||||
const includeNames = power_user.instruct.names || (!!selected_group && power_user.instruct.names_force_groups);
|
const includeNames = power_user.instruct.names || (!!selected_group && power_user.instruct.names_force_groups);
|
||||||
const getOutputSequence = () => power_user.instruct.last_output_sequence || power_user.instruct.output_sequence;
|
const getOutputSequence = () => power_user.instruct.last_output_sequence || power_user.instruct.output_sequence;
|
||||||
|
Reference in New Issue
Block a user