From 3c3eed09965e97b729fd5e3f02b2697bb2ff16d5 Mon Sep 17 00:00:00 2001 From: kingbri Date: Sat, 8 Jul 2023 14:06:35 -0400 Subject: [PATCH] Regex: Change how MD formatting works Previously, there was a checkbox to select placement as MD display. This was counterintuitive since some users believed MD display enclosed the other placement options. Now, add a universal switch to finely tune what parts of a chat should be excluded with MD formatting. For example a regex with the option enabled with AI output selected will only format replies from the character. This is an improvement since users can now choose what parts of a chat to format rather than sticking with a global display specifier. Signed-off-by: kingbri --- public/script.js | 16 ++++++- public/scripts/extensions/regex/editor.html | 12 +++--- public/scripts/extensions/regex/engine.js | 7 ++- public/scripts/extensions/regex/index.js | 48 ++++++++++++++++++--- 4 files changed, 68 insertions(+), 15 deletions(-) diff --git a/public/script.js b/public/script.js index 2c661c201..6d4621b6c 100644 --- a/public/script.js +++ b/public/script.js @@ -446,6 +446,7 @@ const system_messages = { name: systemUserName, force_avatar: system_avatar, is_user: false, + is_system: true, is_name: true, mes: [ '

SillyTavern

', @@ -1137,7 +1138,20 @@ function messageFormatting(mes, ch_name, isSystem, isUser) { mes = mes.replaceAll(substituteParams(power_user.user_prompt_bias), ""); } - mes = getRegexedString(mes, regex_placement.MD_DISPLAY); + if (!isSystem) { + let regexPlacement; + if (isUser) { + regexPlacement = regex_placement.USER_INPUT; + } else if (ch_name === "System") { + regexPlacement = regex_placement.SYSTEM; + } else if (ch_name !== name2) { + regexPlacement = regex_placement.SENDAS; + } else { + regexPlacement = regex_placement.AI_OUTPUT; + } + + mes = getRegexedString(mes, regexPlacement, { isMarkdown: true }); + } if (power_user.auto_fix_generated_markdown) { mes = fixMarkdown(mes); diff --git a/public/scripts/extensions/regex/editor.html b/public/scripts/extensions/regex/editor.html index 7448e474e..f692cf06c 100644 --- a/public/scripts/extensions/regex/editor.html +++ b/public/scripts/extensions/regex/editor.html @@ -56,13 +56,7 @@