also run regex on worldinfo

This commit is contained in:
steve green 2024-05-08 22:55:33 +08:00 committed by steve02081504
parent 10fda0b220
commit d2477bba0c
3 changed files with 20 additions and 3 deletions

View File

@ -68,7 +68,7 @@
</label>
<div>
<textarea
class="regex_trim_strings text_pole wide100p textarea_compact" data-i18n="[placeholder]ext_regex_trim_placeholder"
class="regex_trim_strings text_pole wide100p textarea_compact" data-i18n="[placeholder]ext_regex_trim_placeholder"
placeholder="Globally trims any unwanted parts from a regex match before replacement. Separate each element by an enter."
rows="3"
></textarea>
@ -97,6 +97,12 @@
<span data-i18n="Slash Commands">Slash Commands</span>
</label>
</div>
<div>
<label class="checkbox flex-container">
<input type="checkbox" name="replace_position" value="5">
<span data-i18n="WIAN">WIAN</span>
</label>
</div>
<div class="flex-container wide100p marginTop5">
<div class="flex1 flex-container flexNoGap">
<small data-i18n="[title]ext_regex_min_depth_desc" title="When applied to prompts or display, only affect messages that are at least N levels deep. 0 = last message, 1 = penultimate message, etc. Only counts usable messages, i.e. not hidden or system.">

View File

@ -17,6 +17,8 @@ const regex_placement = {
USER_INPUT: 1,
AI_OUTPUT: 2,
SLASH_COMMAND: 3,
// 4 - sendAs (legacy)
WAIN: 5,
};
/**

View File

@ -10,6 +10,7 @@ import { power_user } from './power-user.js';
import { getTagKeyForEntity } from './tags.js';
import { resolveVariable } from './variables.js';
import { debounce_timeout } from './constants.js';
import { getRegexedString, regex_placement } from './extensions/regex/engine.js';
export {
world_info,
@ -2571,8 +2572,8 @@ async function checkWorldInfo(chat, maxContext) {
}
});
const worldInfoBefore = WIBeforeEntries.length ? WIBeforeEntries.join('\n') : '';
const worldInfoAfter = WIAfterEntries.length ? WIAfterEntries.join('\n') : '';
var worldInfoBefore = WIBeforeEntries.length ? WIBeforeEntries.join('\n') : '';
var worldInfoAfter = WIAfterEntries.length ? WIAfterEntries.join('\n') : '';
if (shouldWIAddPrompt) {
const originalAN = context.extensionPrompts[NOTE_MODULE_NAME].value;
@ -2582,6 +2583,14 @@ async function checkWorldInfo(chat, maxContext) {
buffer.cleanExternalActivations();
{
let regexType = regex_placement.WAIN;
let options = { isPrompt: true, depth: 0 };
worldInfoAfter = getRegexedString(worldInfoAfter, regexType, options);
worldInfoBefore = getRegexedString(worldInfoBefore, regexType, options);
}
return { worldInfoBefore, worldInfoAfter, EMEntries, WIDepthEntries, allActivatedEntries };
}