mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
MesExamples: Make macros consistent with story string
mesExamples in the story string is formatted while mesExamplesRaw is unformatted. However mesExamples when used as a normal macro is unformatted. This causes an inconsistency in usage which is now corrected. Signed-off-by: kingbri <8082010+kingbri1@users.noreply.github.com>
This commit is contained in:
@@ -2716,7 +2716,13 @@ export function substituteParams(content, _name1, _name2, _original, _group, _re
|
|||||||
environment.personality = fields.personality || '';
|
environment.personality = fields.personality || '';
|
||||||
environment.scenario = fields.scenario || '';
|
environment.scenario = fields.scenario || '';
|
||||||
environment.persona = fields.persona || '';
|
environment.persona = fields.persona || '';
|
||||||
environment.mesExamples = fields.mesExamples || '';
|
environment.mesExamples = () => {
|
||||||
|
const isInstruct = power_user.instruct.enabled && main_api !== 'openai';
|
||||||
|
const mesExamplesArray = parseMesExamples(fields.mesExamples, isInstruct);
|
||||||
|
const instructExamples = formatInstructModeExamples(mesExamplesArray, name1, name2);
|
||||||
|
return instructExamples.join('');
|
||||||
|
};
|
||||||
|
environment.mesExamplesRaw = fields.mesExamples || '';
|
||||||
environment.charVersion = fields.version || '';
|
environment.charVersion = fields.version || '';
|
||||||
environment.char_version = fields.version || '';
|
environment.char_version = fields.version || '';
|
||||||
}
|
}
|
||||||
@@ -3105,6 +3111,27 @@ export function getCharacterCardFields() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses an examples string.
|
||||||
|
* @param {string} examplesStr
|
||||||
|
* @returns {string[]} Examples array with block heading
|
||||||
|
*/
|
||||||
|
export function parseMesExamples(examplesStr, isInstruct) {
|
||||||
|
if (!examplesStr || examplesStr.length === 0 || examplesStr === '<START>') {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!examplesStr.startsWith('<START>')) {
|
||||||
|
examplesStr = '<START>\n' + examplesStr.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
const exampleSeparator = power_user.context.example_separator ? `${substituteParams(power_user.context.example_separator)}\n` : '';
|
||||||
|
const blockHeading = main_api === 'openai' ? '<START>\n' : (exampleSeparator || (isInstruct ? '<START>\n' : ''));
|
||||||
|
const splitExamples = examplesStr.split(/<START>/gi).slice(1).map(block => `${blockHeading}${block.trim()}\n`);
|
||||||
|
|
||||||
|
return splitExamples;
|
||||||
|
}
|
||||||
|
|
||||||
export function isStreamingEnabled() {
|
export function isStreamingEnabled() {
|
||||||
const noStreamSources = [chat_completion_sources.SCALE];
|
const noStreamSources = [chat_completion_sources.SCALE];
|
||||||
return (
|
return (
|
||||||
@@ -3993,29 +4020,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
|
|||||||
force_name2 = false;
|
force_name2 = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO (kingbri): Migrate to a utility function
|
let mesExamplesArray = parseMesExamples(mesExamples, isInstruct);
|
||||||
/**
|
|
||||||
* Parses an examples string.
|
|
||||||
* @param {string} examplesStr
|
|
||||||
* @returns {string[]} Examples array with block heading
|
|
||||||
*/
|
|
||||||
function parseMesExamples(examplesStr) {
|
|
||||||
if (!examplesStr || examplesStr.length === 0 || examplesStr === '<START>') {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!examplesStr.startsWith('<START>')) {
|
|
||||||
examplesStr = '<START>\n' + examplesStr.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
const exampleSeparator = power_user.context.example_separator ? `${substituteParams(power_user.context.example_separator)}\n` : '';
|
|
||||||
const blockHeading = main_api === 'openai' ? '<START>\n' : (exampleSeparator || (isInstruct ? '<START>\n' : ''));
|
|
||||||
const splitExamples = examplesStr.split(/<START>/gi).slice(1).map(block => `${blockHeading}${block.trim()}\n`);
|
|
||||||
|
|
||||||
return splitExamples;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mesExamplesArray = parseMesExamples(mesExamples);
|
|
||||||
|
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
// Extension added strings
|
// Extension added strings
|
||||||
@@ -4040,7 +4045,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
|
|||||||
}
|
}
|
||||||
|
|
||||||
const formattedExample = baseChatReplace(exampleMessage, name1, name2);
|
const formattedExample = baseChatReplace(exampleMessage, name1, name2);
|
||||||
const cleanedExample = parseMesExamples(formattedExample);
|
const cleanedExample = parseMesExamples(formattedExample, isInstruct);
|
||||||
|
|
||||||
// Insert depending on before or after position
|
// Insert depending on before or after position
|
||||||
if (example.position === wi_anchor_position.before) {
|
if (example.position === wi_anchor_position.before) {
|
||||||
|
Reference in New Issue
Block a user