mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Allow displaying unreferenced macro in message texts
This commit is contained in:
@ -1540,7 +1540,6 @@ function messageFormatting(mes, ch_name, isSystem, isUser) {
|
|||||||
mes = mes.replaceAll('\\begin{align*}', '$$');
|
mes = mes.replaceAll('\\begin{align*}', '$$');
|
||||||
mes = mes.replaceAll('\\end{align*}', '$$');
|
mes = mes.replaceAll('\\end{align*}', '$$');
|
||||||
mes = converter.makeHtml(mes);
|
mes = converter.makeHtml(mes);
|
||||||
mes = replaceBiasMarkup(mes);
|
|
||||||
|
|
||||||
mes = mes.replace(/<code(.*)>[\s\S]*?<\/code>/g, function (match) {
|
mes = mes.replace(/<code(.*)>[\s\S]*?<\/code>/g, function (match) {
|
||||||
// Firefox creates extra newlines from <br>s in code blocks, so we replace them before converting newlines to <br>s.
|
// Firefox creates extra newlines from <br>s in code blocks, so we replace them before converting newlines to <br>s.
|
||||||
@ -3070,7 +3069,7 @@ async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, qu
|
|||||||
//for normal messages sent from user..
|
//for normal messages sent from user..
|
||||||
if ((textareaText != '' || hasPendingFileAttachment()) && !automatic_trigger && type !== 'quiet' && !dryRun) {
|
if ((textareaText != '' || hasPendingFileAttachment()) && !automatic_trigger && type !== 'quiet' && !dryRun) {
|
||||||
// If user message contains no text other than bias - send as a system message
|
// If user message contains no text other than bias - send as a system message
|
||||||
if (messageBias && replaceBiasMarkup(textareaText).trim().length === 0) {
|
if (messageBias && !removeMacros(textareaText)) {
|
||||||
sendSystemMessage(system_message_types.GENERIC, ' ', { bias: messageBias });
|
sendSystemMessage(system_message_types.GENERIC, ' ', { bias: messageBias });
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -4089,13 +4088,16 @@ function formatMessageHistoryItem(chatItem, isInstruct, forceOutputSequence) {
|
|||||||
textResult = formatInstructModeChat(itemName, chatItem.mes, chatItem.is_user, isNarratorType, chatItem.force_avatar, name1, name2, forceOutputSequence);
|
textResult = formatInstructModeChat(itemName, chatItem.mes, chatItem.is_user, isNarratorType, chatItem.force_avatar, name1, name2, forceOutputSequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
textResult = replaceBiasMarkup(textResult);
|
|
||||||
|
|
||||||
return textResult;
|
return textResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function replaceBiasMarkup(str) {
|
/**
|
||||||
return (str ?? '').replace(/\{\{[\s\S]*?\}\}/gm, '');
|
* Removes all {{macros}} from a string.
|
||||||
|
* @param {string} str String to remove macros from.
|
||||||
|
* @returns {string} String with macros removed.
|
||||||
|
*/
|
||||||
|
export function removeMacros(str) {
|
||||||
|
return (str ?? '').replace(/\{\{[\s\S]*?\}\}/gm, '').trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,7 +21,6 @@ import {
|
|||||||
MAX_INJECTION_DEPTH,
|
MAX_INJECTION_DEPTH,
|
||||||
name1,
|
name1,
|
||||||
name2,
|
name2,
|
||||||
replaceBiasMarkup,
|
|
||||||
replaceItemizedPromptText,
|
replaceItemizedPromptText,
|
||||||
resultCheckStatus,
|
resultCheckStatus,
|
||||||
saveSettingsDebounced,
|
saveSettingsDebounced,
|
||||||
@ -441,8 +440,6 @@ function setOpenAIMessages(chat) {
|
|||||||
content = `${chat[j].name}: ${content}`;
|
content = `${chat[j].name}: ${content}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
content = replaceBiasMarkup(content);
|
|
||||||
|
|
||||||
// remove caret return (waste of tokens)
|
// remove caret return (waste of tokens)
|
||||||
content = content.replace(/\r/gm, '');
|
content = content.replace(/\r/gm, '');
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import {
|
|||||||
main_api,
|
main_api,
|
||||||
name1,
|
name1,
|
||||||
reloadCurrentChat,
|
reloadCurrentChat,
|
||||||
replaceBiasMarkup,
|
removeMacros,
|
||||||
saveChatConditional,
|
saveChatConditional,
|
||||||
sendMessageAsUser,
|
sendMessageAsUser,
|
||||||
sendSystemMessage,
|
sendSystemMessage,
|
||||||
@ -1260,7 +1260,7 @@ export async function sendMessageAs(args, text) {
|
|||||||
|
|
||||||
// Messages that do nothing but set bias will be hidden from the context
|
// Messages that do nothing but set bias will be hidden from the context
|
||||||
const bias = extractMessageBias(mesText);
|
const bias = extractMessageBias(mesText);
|
||||||
const isSystem = replaceBiasMarkup(mesText).trim().length === 0;
|
const isSystem = bias && !removeMacros(mesText).length;
|
||||||
|
|
||||||
const character = characters.find(x => x.name === name);
|
const character = characters.find(x => x.name === name);
|
||||||
let force_avatar, original_avatar;
|
let force_avatar, original_avatar;
|
||||||
@ -1313,7 +1313,7 @@ export async function sendNarratorMessage(args, text) {
|
|||||||
const name = chat_metadata[NARRATOR_NAME_KEY] || NARRATOR_NAME_DEFAULT;
|
const name = chat_metadata[NARRATOR_NAME_KEY] || NARRATOR_NAME_DEFAULT;
|
||||||
// Messages that do nothing but set bias will be hidden from the context
|
// Messages that do nothing but set bias will be hidden from the context
|
||||||
const bias = extractMessageBias(text);
|
const bias = extractMessageBias(text);
|
||||||
const isSystem = replaceBiasMarkup(text).trim().length === 0;
|
const isSystem = bias && !removeMacros(text).length;
|
||||||
|
|
||||||
const message = {
|
const message = {
|
||||||
name: name,
|
name: name,
|
||||||
|
Reference in New Issue
Block a user