Increase maximum injection depth and WI order (#3800)

This commit is contained in:
Cohee
2025-04-13 21:31:57 +03:00
committed by GitHub
parent 57d30dae59
commit 78bda9954d
6 changed files with 31 additions and 18 deletions

View File

@ -5142,7 +5142,7 @@
<div id="persona_depth_position_settings" class="flex-container">
<div class="flex1">
<label for="persona_depth_value" data-i18n="Depth:">Depth:</label>
<input id="persona_depth_value" class="text_pole" type="number" min="0" max="999" step="1">
<input id="persona_depth_value" class="text_pole" type="number" min="0" max="9999" step="1">
</div>
<div class="flex1">
<label for="persona_depth_role" data-i18n="Role:">Role:</label>
@ -5795,7 +5795,7 @@
@ Depth
</span>
</h4>
<input id="depth_prompt_depth" name="depth_prompt_depth" class="text_pole textarea_compact m-t-0" type="number" min="0" max="999" value="4" form="form_create" />
<input id="depth_prompt_depth" name="depth_prompt_depth" class="text_pole textarea_compact m-t-0" type="number" min="0" max="9999" value="4" form="form_create" />
<h4>
<span data-i18n="Role">
Role
@ -6016,11 +6016,11 @@
</div>
<div class="world_entry_form_control wi-enter-footer-text flex-container flexNoGap">
<label for="depth" class="WIEntryHeaderTitleMobile" data-i18n="Depth:">Depth:</label>
<input title="Depth" class="text_pole wideMax100px margin0" type="number" name="depth" data-i18n="[title]Depth" placeholder="" min="0" max="999" />
<input title="Depth" class="text_pole wideMax100px margin0" type="number" name="depth" data-i18n="[title]Depth" placeholder="" min="0" max="9999" />
</div>
<div class="world_entry_form_control wi-enter-footer-text flex-container flexNoGap">
<label for="order" class="WIEntryHeaderTitleMobile" data-i18n="Order:">Order:</label>
<input title="Order" data-i18n="[title]Order" class="text_pole wideMax100px margin0" type="number" name="order" placeholder="" min="0" max="999" />
<input title="Order" data-i18n="[title]Order" class="text_pole wideMax100px margin0" type="number" name="order" placeholder="" min="0" max="9999" />
</div>
<div class="world_entry_form_control wi-enter-footer-text flex-container flexNoGap probabilityContainer">
<label for="order" class="WIEntryHeaderTitleMobile" data-i18n="Trigger %:">Trigger %:</label>
@ -6382,7 +6382,7 @@
<span data-i18n="prompt_manager_depth">Depth</span>
</label>
<div class="text_muted" data-i18n="Injection depth. 0 = after the last message, 1 = before the last message, etc.">Injection depth. 0 = after the last message, 1 = before the last message, etc.</div>
<input id="completion_prompt_manager_popup_entry_form_injection_depth" class="text_pole" type="number" name="injection_depth" min="0" max="999" value="4" />
<input id="completion_prompt_manager_popup_entry_form_injection_depth" class="text_pole" type="number" name="injection_depth" min="0" max="9999" value="4" />
</div>
</div>
<div class="completion_prompt_manager_popup_entry_form_control">
@ -6742,7 +6742,7 @@
<label class="checkbox_label alignItemsCenter" for="extension_floating_position_depth">
<input type="radio" id="extension_floating_position_depth" name="extension_floating_position" value="1" />
<span data-i18n="In-chat @ Depth">In-chat @ Depth</span>
<input id="extension_floating_depth" class="text_pole textarea_compact widthNatural" type="number" min="0" max="999" />
<input id="extension_floating_depth" class="text_pole textarea_compact widthNatural" type="number" min="0" max="9999" />
<span data-i18n="as">as</span>
<select id="extension_floating_role" class="text_pole widthNatural">
<option data-i18n="System" value="0">System</option>
@ -6757,7 +6757,7 @@
<span data-i18n="Insertion Frequency">Insertion Frequency</span>
<small data-i18n="(0 = Disable, 1 = Always)">(0 = Disable, 1 = Always)</small>
</label>
<input id="extension_floating_interval" class="text_pole widthUnset" type="number" min="0" max="999" />
<input id="extension_floating_interval" class="text_pole widthUnset" type="number" min="0" max="9999" />
</div>
<br>
<span><span data-i18n="User inputs until next insertion:">User inputs until next insertion:</span> <span id="extension_floating_counter">(disabled)</span></span>
@ -6827,7 +6827,7 @@
<label class="checkbox_label alignItemsCenter" for="extension_default_position_depth">
<input type="radio" id="extension_default_position_depth" name="extension_default_position" value="1" />
<span data-i18n="In-chat @ Depth">In-chat @ Depth</span>
<input id="extension_default_depth" class="text_pole textarea_compact widthNatural" type="number" min="0" max="999" />
<input id="extension_default_depth" class="text_pole textarea_compact widthNatural" type="number" min="0" max="9999" />
<span data-i18n="as">as</span>
<select id="extension_default_role" class="text_pole widthNatural">
<option data-i18n="System" value="0">System</option>
@ -6841,7 +6841,7 @@
<span data-i18n="Insertion Frequency">Insertion Frequency</span>
<small data-i18n="(0 = Disable, 1 = Always)">(0 = Disable, 1 = Always)</small>
</label>
<input id="extension_default_interval" class="text_pole widthUnset" type="number" min="0" max="999" />
<input id="extension_default_interval" class="text_pole widthUnset" type="number" min="0" max="9999" />
</div>
</div>
</div>

View File

@ -651,7 +651,7 @@ export const extension_prompt_roles = {
ASSISTANT: 2,
};
export const MAX_INJECTION_DEPTH = 1000;
export const MAX_INJECTION_DEPTH = 10000;
const SAFETY_CHAT = [
{
@ -3046,6 +3046,17 @@ export async function getExtensionPromptByName(moduleName) {
return substituteParams(prompt.value);
}
/**
* Gets the maximum depth of extension prompts.
* @returns {number} Maximum depth of extension prompts
*/
export function getExtensionPromptMaxDepth() {
const prompts = Object.values(extension_prompts);
const maxDepth = Math.max(...prompts.map(x => x.depth ?? 0));
// Clamp to 1 <= depth <= MAX_INJECTION_DEPTH
return Math.max(Math.min(maxDepth, MAX_INJECTION_DEPTH), 1);
}
/**
* Returns the extension prompt for the given position, depth, and role.
* If multiple prompts are found, they are joined with a separator.
@ -5099,7 +5110,8 @@ async function doChatInject(messages, isContinue) {
let totalInsertedMessages = 0;
messages.reverse();
for (let i = 0; i <= MAX_INJECTION_DEPTH; i++) {
const maxDepth = getExtensionPromptMaxDepth();
for (let i = 0; i <= maxDepth; i++) {
// Order of priority (most important go lower)
const roles = [extension_prompt_roles.SYSTEM, extension_prompt_roles.USER, extension_prompt_roles.ASSISTANT];
const names = {

View File

@ -132,7 +132,7 @@
</label>
<label class="flex-container alignItemsCenter" title="How many messages before the current end of the chat." data-i18n="[title]How many messages before the current end of the chat.">
<input type="radio" name="memory_position" value="1" />
<span data-i18n="In-chat @ Depth">In-chat @ Depth</span> <input id="memory_depth" class="text_pole widthUnset" type="number" min="0" max="999" />
<span data-i18n="In-chat @ Depth">In-chat @ Depth</span> <input id="memory_depth" class="text_pole widthUnset" type="number" min="0" max="9999" />
<span data-i18n="as">as</span>
<select id="memory_role" class="text_pole widthNatural">
<option value="0" data-i18n="System">System</option>

View File

@ -113,14 +113,14 @@
<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="-1" max="999" data-i18n="[placeholder]ext_regex_min_depth_placeholder" placeholder="Unlimited" />
<input name="min_depth" class="text_pole textarea_compact" type="number" min="-1" max="9999" 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. System prompt and utility prompts are not affected. Max must be greater than Min for regex to apply.">
<span data-i18n="Max Depth">Max Depth</span>
<span class="fa-solid fa-circle-question note-link-span"></span>
</small>
<input name="max_depth" class="text_pole textarea_compact" type="number" min="0" max="999" data-i18n="[placeholder]ext_regex_min_depth_placeholder" placeholder="Unlimited" />
<input name="max_depth" class="text_pole textarea_compact" type="number" min="0" max="9999" data-i18n="[placeholder]ext_regex_min_depth_placeholder" placeholder="Unlimited" />
</div>
</div>
</div>

View File

@ -310,7 +310,7 @@
<label for="vectors_file_depth_db" title="How many messages before the current end of the chat." data-i18n="[title]How many messages before the current end of the chat.">
<input type="radio" name="vectors_file_position_db" value="1" />
<span data-i18n="In-chat @ Depth">In-chat @ Depth</span>
<input id="vectors_file_depth_db" class="text_pole widthUnset" type="number" min="0" max="999" />
<input id="vectors_file_depth_db" class="text_pole widthUnset" type="number" min="0" max="9999" />
<span>as</span>
<select id="vectors_file_depth_role_db" class="text_pole widthNatural">
<option value="0" data-i18n="System">System</option>
@ -362,7 +362,7 @@
<label for="vectors_depth" title="How many messages before the current end of the chat." data-i18n="[title]How many messages before the current end of the chat.">
<input type="radio" name="vectors_position" value="1" />
<span data-i18n="In-chat @ Depth">In-chat @ Depth </span>
<input id="vectors_depth" class="text_pole widthUnset" type="number" min="0" max="999" />
<input id="vectors_depth" class="text_pole widthUnset" type="number" min="0" max="9999" />
</label>
</div>
<div class="flex-container">

View File

@ -15,12 +15,12 @@ import {
extension_prompt_types,
Generate,
getExtensionPrompt,
getExtensionPromptMaxDepth,
getNextMessageId,
getRequestHeaders,
getStoppingStrings,
is_send_press,
main_api,
MAX_INJECTION_DEPTH,
name1,
name2,
replaceItemizedPromptText,
@ -742,7 +742,8 @@ async function populationInjectionPrompts(prompts, messages) {
'assistant': extension_prompt_roles.ASSISTANT,
};
for (let i = 0; i <= MAX_INJECTION_DEPTH; i++) {
const maxDepth = getExtensionPromptMaxDepth();
for (let i = 0; i <= maxDepth; i++) {
// Get prompts for current depth
const depthPrompts = prompts.filter(prompt => prompt.injection_depth === i && prompt.content);