mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add instruct input/output sequence macro replacing
This commit is contained in:
@ -1774,7 +1774,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
const magName = isImpersonate ? (is_pygmalion ? 'You' : name1) : name2;
|
const magName = isImpersonate ? (is_pygmalion ? 'You' : name1) : name2;
|
||||||
|
|
||||||
if (isInstruct) {
|
if (isInstruct) {
|
||||||
message_already_generated = formatInstructModePrompt(magName, isImpersonate);
|
message_already_generated = formatInstructModePrompt(magName, isImpersonate, false, name1, name2);
|
||||||
} else {
|
} else {
|
||||||
message_already_generated = `${magName}: `;
|
message_already_generated = `${magName}: `;
|
||||||
}
|
}
|
||||||
@ -2116,14 +2116,14 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
// Add quiet generation prompt at depth 0
|
// Add quiet generation prompt at depth 0
|
||||||
if (quiet_prompt && quiet_prompt.length) {
|
if (quiet_prompt && quiet_prompt.length) {
|
||||||
const name = is_pygmalion ? 'You' : name1;
|
const name = is_pygmalion ? 'You' : name1;
|
||||||
const quietAppend = isInstruct ? formatInstructModeChat(name, quiet_prompt, false, true, false) : `\n${name}: ${quiet_prompt}`;
|
const quietAppend = isInstruct ? formatInstructModeChat(name, quiet_prompt, false, true, false, name1, name2) : `\n${name}: ${quiet_prompt}`;
|
||||||
mesSendString += quietAppend;
|
mesSendString += quietAppend;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get instruct mode line
|
// Get instruct mode line
|
||||||
if (isInstruct && tokens_already_generated === 0) {
|
if (isInstruct && tokens_already_generated === 0) {
|
||||||
const name = isImpersonate ? (is_pygmalion ? 'You' : name1) : name2;
|
const name = isImpersonate ? (is_pygmalion ? 'You' : name1) : name2;
|
||||||
mesSendString += formatInstructModePrompt(name, isImpersonate, promptBias);
|
mesSendString += formatInstructModePrompt(name, isImpersonate, promptBias, name1, name2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get non-instruct impersonation line
|
// Get non-instruct impersonation line
|
||||||
@ -2541,7 +2541,7 @@ function formatMessageHistoryItem(chatItem, isInstruct) {
|
|||||||
let textResult = shouldPrependName ? `${itemName}: ${chatItem.mes}\n` : `${chatItem.mes}\n`;
|
let textResult = shouldPrependName ? `${itemName}: ${chatItem.mes}\n` : `${chatItem.mes}\n`;
|
||||||
|
|
||||||
if (isInstruct) {
|
if (isInstruct) {
|
||||||
textResult = formatInstructModeChat(itemName, chatItem.mes, chatItem.is_user, isNarratorType, chatItem.force_avatar);
|
textResult = formatInstructModeChat(itemName, chatItem.mes, chatItem.is_user, isNarratorType, chatItem.force_avatar, name1, name2);
|
||||||
}
|
}
|
||||||
|
|
||||||
textResult = replaceBiasMarkup(textResult);
|
textResult = replaceBiasMarkup(textResult);
|
||||||
|
@ -641,9 +641,14 @@ function loadInstructMode() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvatar) {
|
export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvatar, name1, name2) {
|
||||||
const includeNames = isNarrator ? false : (power_user.instruct.names || !!selected_group || !!forceAvatar);
|
const includeNames = isNarrator ? false : (power_user.instruct.names || !!selected_group || !!forceAvatar);
|
||||||
const sequence = (isUser || isNarrator) ? power_user.instruct.input_sequence : power_user.instruct.output_sequence;
|
const sequence = substituteParams(
|
||||||
|
(isUser || isNarrator) ? power_user.instruct.input_sequence : power_user.instruct.output_sequence,
|
||||||
|
name1,
|
||||||
|
name2
|
||||||
|
);
|
||||||
|
|
||||||
const separator = power_user.instruct.wrap ? '\n' : '';
|
const separator = power_user.instruct.wrap ? '\n' : '';
|
||||||
const separatorSequence = power_user.instruct.separator_sequence && !isUser
|
const separatorSequence = power_user.instruct.separator_sequence && !isUser
|
||||||
? power_user.instruct.separator_sequence
|
? power_user.instruct.separator_sequence
|
||||||
@ -662,9 +667,14 @@ export function formatInstructStoryString(story) {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatInstructModePrompt(name, isImpersonate, promptBias) {
|
export function formatInstructModePrompt(name, isImpersonate, promptBias, name1, name2) {
|
||||||
const includeNames = power_user.instruct.names || !!selected_group;
|
const includeNames = power_user.instruct.names || !!selected_group;
|
||||||
const sequence = isImpersonate ? power_user.instruct.input_sequence : power_user.instruct.output_sequence;
|
const sequence = substituteParams(
|
||||||
|
isImpersonate ? power_user.instruct.input_sequence : power_user.instruct.output_sequence,
|
||||||
|
name1,
|
||||||
|
name2
|
||||||
|
);
|
||||||
|
|
||||||
const separator = power_user.instruct.wrap ? '\n' : '';
|
const separator = power_user.instruct.wrap ? '\n' : '';
|
||||||
let text = includeNames ? (separator + sequence + separator + `${name}:`) : (separator + sequence);
|
let text = includeNames ? (separator + sequence + separator + `${name}:`) : (separator + sequence);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user