Merge pull request #2193 from steve02081504/patch-2
also run regex on worldinfo
This commit is contained in:
commit
0587931cae
|
@ -79,34 +79,40 @@
|
||||||
<div class="flex-container">
|
<div class="flex-container">
|
||||||
<div class="flex1 wi-enter-footer-text flex-container flexFlowColumn flexNoGap alignitemsstart">
|
<div class="flex1 wi-enter-footer-text flex-container flexFlowColumn flexNoGap alignitemsstart">
|
||||||
<small data-i18n="ext_regex_affects">Affects</small>
|
<small data-i18n="ext_regex_affects">Affects</small>
|
||||||
<div>
|
<div title="Messages sent by the user.">
|
||||||
<label class="checkbox flex-container">
|
<label class="checkbox flex-container">
|
||||||
<input type="checkbox" name="replace_position" value="1">
|
<input type="checkbox" name="replace_position" value="1">
|
||||||
<span data-i18n="ext_regex_user_input">User Input</span>
|
<span data-i18n="ext_regex_user_input">User Input</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div title="Messages received from the Generation API.">
|
||||||
<label class="checkbox flex-container">
|
<label class="checkbox flex-container">
|
||||||
<input type="checkbox" name="replace_position" value="2">
|
<input type="checkbox" name="replace_position" value="2">
|
||||||
<span data-i18n="ext_regex_ai_output">AI Output</span>
|
<span data-i18n="ext_regex_ai_output">AI Output</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div title="Messages sent using STscript commands.">
|
||||||
<label class="checkbox flex-container">
|
<label class="checkbox flex-container">
|
||||||
<input type="checkbox" name="replace_position" value="3">
|
<input type="checkbox" name="replace_position" value="3">
|
||||||
<span data-i18n="Slash Commands">Slash Commands</span>
|
<span data-i18n="Slash Commands">Slash Commands</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div title="Lorebook/World Info entry contents. Requires 'Only Format Prompt' to be checked!">
|
||||||
|
<label class="checkbox flex-container">
|
||||||
|
<input type="checkbox" name="replace_position" value="5">
|
||||||
|
<span data-i18n="World Info">World Info</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
<div class="flex-container wide100p marginTop5">
|
<div class="flex-container wide100p marginTop5">
|
||||||
<div class="flex1 flex-container flexNoGap">
|
<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.">
|
<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 WI entries @Depth and usable messages, i.e. not hidden or system.">
|
||||||
<span data-i18n="Min Depth">Min Depth</span>
|
<span data-i18n="Min Depth">Min Depth</span>
|
||||||
<span class="fa-solid fa-circle-question note-link-span"></span>
|
<span class="fa-solid fa-circle-question note-link-span"></span>
|
||||||
</small>
|
</small>
|
||||||
<input name="min_depth" class="text_pole textarea_compact" type="number" min="0" max="999" data-i18n="[placeholder]ext_regex_min_depth_placeholder" placeholder="Unlimited" />
|
<input name="min_depth" class="text_pole textarea_compact" type="number" min="0" max="999" data-i18n="[placeholder]ext_regex_min_depth_placeholder" placeholder="Unlimited" />
|
||||||
</div>
|
</div>
|
||||||
<div class="flex1 flex-container flexNoGap">
|
<div class="flex1 flex-container flexNoGap">
|
||||||
<small data-i18n="[title]ext_regex_max_depth_desc" title="When applied to prompts or display, only affect messages no more than N levels deep. 0 = last message, 1 = penultimate message, etc. Only counts usable messages, i.e. not hidden or system.">
|
<small data-i18n="[title]ext_regex_max_depth_desc" title="When applied to prompts or display, only affect messages no more than N levels deep. 0 = last message, 1 = penultimate message, etc. Only counts WI entries @Depth and usable messages, i.e. not hidden or system.">
|
||||||
<span data-i18n="Max Depth">Max Depth</span>
|
<span data-i18n="Max Depth">Max Depth</span>
|
||||||
<span class="fa-solid fa-circle-question note-link-span"></span>
|
<span class="fa-solid fa-circle-question note-link-span"></span>
|
||||||
</small>
|
</small>
|
||||||
|
@ -120,11 +126,11 @@
|
||||||
<input type="checkbox" name="disabled" />
|
<input type="checkbox" name="disabled" />
|
||||||
<span data-i18n="Disabled">Disabled</span>
|
<span data-i18n="Disabled">Disabled</span>
|
||||||
</label>
|
</label>
|
||||||
<label class="checkbox flex-container">
|
<label class="checkbox flex-container" title="Chat history won't change, only the message rendered in the UI.">
|
||||||
<input type="checkbox" name="only_format_display" />
|
<input type="checkbox" name="only_format_display" />
|
||||||
<span data-i18n="Only Format Display">Only Format Display</span>
|
<span data-i18n="Only Format Display">Only Format Display</span>
|
||||||
</label>
|
</label>
|
||||||
<label class="checkbox flex-container" data-i18n="[title]ext_regex_only_format_prompt_desc" title="Chat history won't change, only the prompt as the request is sent (on generation)">
|
<label class="checkbox flex-container" data-i18n="[title]ext_regex_only_format_prompt_desc" title="Chat history won't change, only the prompt as the request is sent (on generation).">
|
||||||
<input type="checkbox" name="only_format_prompt"/>
|
<input type="checkbox" name="only_format_prompt"/>
|
||||||
<span>
|
<span>
|
||||||
<span data-i18n="Only Format Prompt (?)">Only Format Prompt</span>
|
<span data-i18n="Only Format Prompt (?)">Only Format Prompt</span>
|
||||||
|
@ -135,7 +141,7 @@
|
||||||
<input type="checkbox" name="run_on_edit" />
|
<input type="checkbox" name="run_on_edit" />
|
||||||
<span data-i18n="Run On Edit">Run On Edit</span>
|
<span data-i18n="Run On Edit">Run On Edit</span>
|
||||||
</label>
|
</label>
|
||||||
<label class="checkbox flex-container" data-i18n="[title]ext_regex_substitute_regex_desc" title="Substitute {{macros}} in Find Regex before running it">
|
<label class="checkbox flex-container" data-i18n="[title]ext_regex_substitute_regex_desc" title="Substitute {{macros}} in Find Regex before running it">
|
||||||
<input type="checkbox" name="substitute_regex" />
|
<input type="checkbox" name="substitute_regex" />
|
||||||
<span>
|
<span>
|
||||||
<span data-i18n="Substitute Regex">Substitute Regex</span>
|
<span data-i18n="Substitute Regex">Substitute Regex</span>
|
||||||
|
|
|
@ -17,6 +17,8 @@ const regex_placement = {
|
||||||
USER_INPUT: 1,
|
USER_INPUT: 1,
|
||||||
AI_OUTPUT: 2,
|
AI_OUTPUT: 2,
|
||||||
SLASH_COMMAND: 3,
|
SLASH_COMMAND: 3,
|
||||||
|
// 4 - sendAs (legacy)
|
||||||
|
WORLD_INFO: 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { power_user } from './power-user.js';
|
||||||
import { getTagKeyForEntity } from './tags.js';
|
import { getTagKeyForEntity } from './tags.js';
|
||||||
import { resolveVariable } from './variables.js';
|
import { resolveVariable } from './variables.js';
|
||||||
import { debounce_timeout } from './constants.js';
|
import { debounce_timeout } from './constants.js';
|
||||||
|
import { getRegexedString, regex_placement } from './extensions/regex/engine.js';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
world_info,
|
world_info,
|
||||||
|
@ -2530,37 +2531,40 @@ async function checkWorldInfo(chat, maxContext) {
|
||||||
// Appends from insertion order 999 to 1. Use unshift for this purpose
|
// Appends from insertion order 999 to 1. Use unshift for this purpose
|
||||||
// TODO (kingbri): Change to use WI Anchor positioning instead of separate top/bottom arrays
|
// TODO (kingbri): Change to use WI Anchor positioning instead of separate top/bottom arrays
|
||||||
[...allActivatedEntries].sort(sortFn).forEach((entry) => {
|
[...allActivatedEntries].sort(sortFn).forEach((entry) => {
|
||||||
|
const regexDepth = entry.position === world_info_position.atDepth ? (entry.depth ?? DEFAULT_DEPTH) : null;
|
||||||
|
const content = getRegexedString(entry.content, regex_placement.WORLD_INFO, { depth: regexDepth, isMarkdown: false, isPrompt: true });
|
||||||
|
|
||||||
switch (entry.position) {
|
switch (entry.position) {
|
||||||
case world_info_position.before:
|
case world_info_position.before:
|
||||||
WIBeforeEntries.unshift(substituteParams(entry.content));
|
WIBeforeEntries.unshift(substituteParams(content));
|
||||||
break;
|
break;
|
||||||
case world_info_position.after:
|
case world_info_position.after:
|
||||||
WIAfterEntries.unshift(substituteParams(entry.content));
|
WIAfterEntries.unshift(substituteParams(content));
|
||||||
break;
|
break;
|
||||||
case world_info_position.EMTop:
|
case world_info_position.EMTop:
|
||||||
EMEntries.unshift(
|
EMEntries.unshift(
|
||||||
{ position: wi_anchor_position.before, content: entry.content },
|
{ position: wi_anchor_position.before, content: content },
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case world_info_position.EMBottom:
|
case world_info_position.EMBottom:
|
||||||
EMEntries.unshift(
|
EMEntries.unshift(
|
||||||
{ position: wi_anchor_position.after, content: entry.content },
|
{ position: wi_anchor_position.after, content: content },
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case world_info_position.ANTop:
|
case world_info_position.ANTop:
|
||||||
ANTopEntries.unshift(entry.content);
|
ANTopEntries.unshift(content);
|
||||||
break;
|
break;
|
||||||
case world_info_position.ANBottom:
|
case world_info_position.ANBottom:
|
||||||
ANBottomEntries.unshift(entry.content);
|
ANBottomEntries.unshift(content);
|
||||||
break;
|
break;
|
||||||
case world_info_position.atDepth: {
|
case world_info_position.atDepth: {
|
||||||
const existingDepthIndex = WIDepthEntries.findIndex((e) => e.depth === (entry.depth ?? DEFAULT_DEPTH) && e.role === (entry.role ?? extension_prompt_roles.SYSTEM));
|
const existingDepthIndex = WIDepthEntries.findIndex((e) => e.depth === (entry.depth ?? DEFAULT_DEPTH) && e.role === (entry.role ?? extension_prompt_roles.SYSTEM));
|
||||||
if (existingDepthIndex !== -1) {
|
if (existingDepthIndex !== -1) {
|
||||||
WIDepthEntries[existingDepthIndex].entries.unshift(entry.content);
|
WIDepthEntries[existingDepthIndex].entries.unshift(content);
|
||||||
} else {
|
} else {
|
||||||
WIDepthEntries.push({
|
WIDepthEntries.push({
|
||||||
depth: entry.depth,
|
depth: entry.depth,
|
||||||
entries: [entry.content],
|
entries: [content],
|
||||||
role: entry.role ?? extension_prompt_roles.SYSTEM,
|
role: entry.role ?? extension_prompt_roles.SYSTEM,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue