mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-01-20 21:41:32 +01:00
Fix naming and improve regex application
This commit is contained in:
parent
d2477bba0c
commit
3c0664dfb6
@ -79,40 +79,40 @@
|
||||
<div class="flex-container">
|
||||
<div class="flex1 wi-enter-footer-text flex-container flexFlowColumn flexNoGap alignitemsstart">
|
||||
<small data-i18n="ext_regex_affects">Affects</small>
|
||||
<div>
|
||||
<div title="Messages sent by the user.">
|
||||
<label class="checkbox flex-container">
|
||||
<input type="checkbox" name="replace_position" value="1">
|
||||
<span data-i18n="ext_regex_user_input">User Input</span>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<div title="Messages received from the Generation API.">
|
||||
<label class="checkbox flex-container">
|
||||
<input type="checkbox" name="replace_position" value="2">
|
||||
<span data-i18n="ext_regex_ai_output">AI Output</span>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<div title="Messages sent using STscript commands.">
|
||||
<label class="checkbox flex-container">
|
||||
<input type="checkbox" name="replace_position" value="3">
|
||||
<span data-i18n="Slash Commands">Slash Commands</span>
|
||||
</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="WIAN">WIAN</span>
|
||||
<span data-i18n="World Info">World Info</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.">
|
||||
<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 class="fa-solid fa-circle-question note-link-span"></span>
|
||||
</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" />
|
||||
</div>
|
||||
<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 class="fa-solid fa-circle-question note-link-span"></span>
|
||||
</small>
|
||||
@ -126,11 +126,11 @@
|
||||
<input type="checkbox" name="disabled" />
|
||||
<span data-i18n="Disabled">Disabled</span>
|
||||
</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" />
|
||||
<span data-i18n="Only Format Display">Only Format Display</span>
|
||||
</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"/>
|
||||
<span>
|
||||
<span data-i18n="Only Format Prompt (?)">Only Format Prompt</span>
|
||||
@ -141,7 +141,7 @@
|
||||
<input type="checkbox" name="run_on_edit" />
|
||||
<span data-i18n="Run On Edit">Run On Edit</span>
|
||||
</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" />
|
||||
<span>
|
||||
<span data-i18n="Substitute Regex">Substitute Regex</span>
|
||||
|
@ -18,7 +18,7 @@ const regex_placement = {
|
||||
AI_OUTPUT: 2,
|
||||
SLASH_COMMAND: 3,
|
||||
// 4 - sendAs (legacy)
|
||||
WAIN: 5,
|
||||
WORLD_INFO: 5,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -2531,37 +2531,40 @@ async function checkWorldInfo(chat, maxContext) {
|
||||
// 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
|
||||
[...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) {
|
||||
case world_info_position.before:
|
||||
WIBeforeEntries.unshift(substituteParams(entry.content));
|
||||
WIBeforeEntries.unshift(substituteParams(content));
|
||||
break;
|
||||
case world_info_position.after:
|
||||
WIAfterEntries.unshift(substituteParams(entry.content));
|
||||
WIAfterEntries.unshift(substituteParams(content));
|
||||
break;
|
||||
case world_info_position.EMTop:
|
||||
EMEntries.unshift(
|
||||
{ position: wi_anchor_position.before, content: entry.content },
|
||||
{ position: wi_anchor_position.before, content: content },
|
||||
);
|
||||
break;
|
||||
case world_info_position.EMBottom:
|
||||
EMEntries.unshift(
|
||||
{ position: wi_anchor_position.after, content: entry.content },
|
||||
{ position: wi_anchor_position.after, content: content },
|
||||
);
|
||||
break;
|
||||
case world_info_position.ANTop:
|
||||
ANTopEntries.unshift(entry.content);
|
||||
ANTopEntries.unshift(content);
|
||||
break;
|
||||
case world_info_position.ANBottom:
|
||||
ANBottomEntries.unshift(entry.content);
|
||||
ANBottomEntries.unshift(content);
|
||||
break;
|
||||
case world_info_position.atDepth: {
|
||||
const existingDepthIndex = WIDepthEntries.findIndex((e) => e.depth === (entry.depth ?? DEFAULT_DEPTH) && e.role === (entry.role ?? extension_prompt_roles.SYSTEM));
|
||||
if (existingDepthIndex !== -1) {
|
||||
WIDepthEntries[existingDepthIndex].entries.unshift(entry.content);
|
||||
WIDepthEntries[existingDepthIndex].entries.unshift(content);
|
||||
} else {
|
||||
WIDepthEntries.push({
|
||||
depth: entry.depth,
|
||||
entries: [entry.content],
|
||||
entries: [content],
|
||||
role: entry.role ?? extension_prompt_roles.SYSTEM,
|
||||
});
|
||||
}
|
||||
@ -2583,14 +2586,6 @@ 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 };
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user