Increase maximum injection depth and WI order (#3800)

78bda9954d3d8f3b8eb175e42918324d2ae65b47

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
6 files changed, +31 -18Showing whitespace changes
public/index.html+9 -9
@@ -5142,7 +5142,7 @@
51425142 <div id="persona_depth_position_settings" class="flex-container">
51435143 <div class="flex1">
51445144 <label for="persona_depth_value" data-i18n="Depth:">Depth:</label>
51455145 <input id="persona_depth_value" class="text_pole" type="number" min="0" max="9999999" step="1">
51465146 </div>
51475147 <div class="flex1">
51485148 <label for="persona_depth_role" data-i18n="Role:">Role:</label>
@@ -5795,7 +5795,7 @@
57955795 @ Depth
57965796 </span>
57975797 </h4>
57985798 <input id="depth_prompt_depth" name="depth_prompt_depth" class="text_pole textarea_compact m-t-0" type="number" min="0" max="9999999" value="4" form="form_create" />
57995799 <h4>
58005800 <span data-i18n="Role">
58015801 Role
@@ -6016,11 +6016,11 @@
60166016 </div>
60176017 <div class="world_entry_form_control wi-enter-footer-text flex-container flexNoGap">
60186018 <label for="depth" class="WIEntryHeaderTitleMobile" data-i18n="Depth:">Depth:</label>
60196019 <input title="Depth" class="text_pole wideMax100px margin0" type="number" name="depth" data-i18n="[title]Depth" placeholder="" min="0" max="9999999" />
60206020 </div>
60216021 <div class="world_entry_form_control wi-enter-footer-text flex-container flexNoGap">
60226022 <label for="order" class="WIEntryHeaderTitleMobile" data-i18n="Order:">Order:</label>
60236023 <input title="Order" data-i18n="[title]Order" class="text_pole wideMax100px margin0" type="number" name="order" placeholder="" min="0" max="9999999" />
60246024 </div>
60256025 <div class="world_entry_form_control wi-enter-footer-text flex-container flexNoGap probabilityContainer">
60266026 <label for="order" class="WIEntryHeaderTitleMobile" data-i18n="Trigger %:">Trigger %:</label>
@@ -6382,7 +6382,7 @@
63826382 <span data-i18n="prompt_manager_depth">Depth</span>
63836383 </label>
63846384 <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>
63856385 <input id="completion_prompt_manager_popup_entry_form_injection_depth" class="text_pole" type="number" name="injection_depth" min="0" max="9999999" value="4" />
63866386 </div>
63876387 </div>
63886388 <div class="completion_prompt_manager_popup_entry_form_control">
@@ -6742,7 +6742,7 @@
67426742 <label class="checkbox_label alignItemsCenter" for="extension_floating_position_depth">
67436743 <input type="radio" id="extension_floating_position_depth" name="extension_floating_position" value="1" />
67446744 <span data-i18n="In-chat @ Depth">In-chat @ Depth</span>
67456745 <input id="extension_floating_depth" class="text_pole textarea_compact widthNatural" type="number" min="0" max="9999999" />
67466746 <span data-i18n="as">as</span>
67476747 <select id="extension_floating_role" class="text_pole widthNatural">
67486748 <option data-i18n="System" value="0">System</option>
@@ -6757,7 +6757,7 @@
67576757 <span data-i18n="Insertion Frequency">Insertion Frequency</span>
67586758 <small data-i18n="(0 = Disable, 1 = Always)">(0 = Disable, 1 = Always)</small>
67596759 </label>
67606760 <input id="extension_floating_interval" class="text_pole widthUnset" type="number" min="0" max="9999999" />
67616761 </div>
67626762 <br>
67636763 <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 @@
68276827 <label class="checkbox_label alignItemsCenter" for="extension_default_position_depth">
68286828 <input type="radio" id="extension_default_position_depth" name="extension_default_position" value="1" />
68296829 <span data-i18n="In-chat @ Depth">In-chat @ Depth</span>
68306830 <input id="extension_default_depth" class="text_pole textarea_compact widthNatural" type="number" min="0" max="9999999" />
68316831 <span data-i18n="as">as</span>
68326832 <select id="extension_default_role" class="text_pole widthNatural">
68336833 <option data-i18n="System" value="0">System</option>
@@ -6841,7 +6841,7 @@
68416841 <span data-i18n="Insertion Frequency">Insertion Frequency</span>
68426842 <small data-i18n="(0 = Disable, 1 = Always)">(0 = Disable, 1 = Always)</small>
68436843 </label>
68446844 <input id="extension_default_interval" class="text_pole widthUnset" type="number" min="0" max="9999999" />
68456845 </div>
68466846 </div>
68476847 </div>
public/script.js+14 -2
@@ -651,7 +651,7 @@ export const extension_prompt_roles = {
651651 ASSISTANT: 2,
652652};
653653
654654export const MAX_INJECTION_DEPTH = 100010000;
655655
656656const SAFETY_CHAT = [
657657 {
@@ -3047,6 +3047,17 @@ export async function getExtensionPromptByName(moduleName) {
30473047}
30483048
30493049/**
3050+ * Gets the maximum depth of extension prompts.
3051+ * @returns {number} Maximum depth of extension prompts
3052+ */
3053+export function getExtensionPromptMaxDepth() {
3054+ const prompts = Object.values(extension_prompts);
3055+ const maxDepth = Math.max(...prompts.map(x => x.depth ?? 0));
3056+ // Clamp to 1 <= depth <= MAX_INJECTION_DEPTH
3057+ return Math.max(Math.min(maxDepth, MAX_INJECTION_DEPTH), 1);
3058+}
3059+
3060+/**
30503061 * Returns the extension prompt for the given position, depth, and role.
30513062 * If multiple prompts are found, they are joined with a separator.
30523063 * @param {number} [position] Position of the prompt
@@ -5099,7 +5110,8 @@ async function doChatInject(messages, isContinue) {
50995110 let totalInsertedMessages = 0;
51005111 messages.reverse();
51015112
5102- for (let i = 0; i <= MAX_INJECTION_DEPTH; i++) {
5113+ const maxDepth = getExtensionPromptMaxDepth();
5114+ for (let i = 0; i <= maxDepth; i++) {
51035115 // Order of priority (most important go lower)
51045116 const roles = [extension_prompt_roles.SYSTEM, extension_prompt_roles.USER, extension_prompt_roles.ASSISTANT];
51055117 const names = {
public/scripts/extensions/memory/settings.html+1 -1
@@ -132,7 +132,7 @@
132132 </label>
133133 <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.">
134134 <input type="radio" name="memory_position" value="1" />
135135 <span data-i18n="In-chat @ Depth">In-chat @ Depth</span> <input id="memory_depth" class="text_pole widthUnset" type="number" min="0" max="9999999" />
136136 <span data-i18n="as">as</span>
137137 <select id="memory_role" class="text_pole widthNatural">
138138 <option value="0" data-i18n="System">System</option>
public/scripts/extensions/regex/editor.html+2 -2
@@ -113,14 +113,14 @@
113113 <span data-i18n="Min Depth">Min Depth</span>
114114 <span class="fa-solid fa-circle-question note-link-span"></span>
115115 </small>
116116 <input name="min_depth" class="text_pole textarea_compact" type="number" min="-1" max="9999999" data-i18n="[placeholder]ext_regex_min_depth_placeholder" placeholder="Unlimited" />
117117 </div>
118118 <div class="flex1 flex-container flexNoGap">
119119 <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.">
120120 <span data-i18n="Max Depth">Max Depth</span>
121121 <span class="fa-solid fa-circle-question note-link-span"></span>
122122 </small>
123123 <input name="max_depth" class="text_pole textarea_compact" type="number" min="0" max="9999999" data-i18n="[placeholder]ext_regex_min_depth_placeholder" placeholder="Unlimited" />
124124 </div>
125125 </div>
126126 </div>
public/scripts/extensions/vectors/settings.html+2 -2
@@ -310,7 +310,7 @@
310310 <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.">
311311 <input type="radio" name="vectors_file_position_db" value="1" />
312312 <span data-i18n="In-chat @ Depth">In-chat @ Depth</span>
313313 <input id="vectors_file_depth_db" class="text_pole widthUnset" type="number" min="0" max="9999999" />
314314 <span>as</span>
315315 <select id="vectors_file_depth_role_db" class="text_pole widthNatural">
316316 <option value="0" data-i18n="System">System</option>
@@ -362,7 +362,7 @@
362362 <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.">
363363 <input type="radio" name="vectors_position" value="1" />
364364 <span data-i18n="In-chat @ Depth">In-chat @ Depth </span>
365365 <input id="vectors_depth" class="text_pole widthUnset" type="number" min="0" max="9999999" />
366366 </label>
367367 </div>
368368 <div class="flex-container">
public/scripts/openai.js+3 -2
@@ -15,12 +15,12 @@ import {
1515 extension_prompt_types,
1616 Generate,
1717 getExtensionPrompt,
18+ getExtensionPromptMaxDepth,
1819 getNextMessageId,
1920 getRequestHeaders,
2021 getStoppingStrings,
2122 is_send_press,
2223 main_api,
23- MAX_INJECTION_DEPTH,
2424 name1,
2525 name2,
2626 replaceItemizedPromptText,
@@ -742,7 +742,8 @@ async function populationInjectionPrompts(prompts, messages) {
742742 'assistant': extension_prompt_roles.ASSISTANT,
743743 };
744744
745- for (let i = 0; i <= MAX_INJECTION_DEPTH; i++) {
745+ const maxDepth = getExtensionPromptMaxDepth();
746+ for (let i = 0; i <= maxDepth; i++) {
746747 // Get prompts for current depth
747748 const depthPrompts = prompts.filter(prompt => prompt.injection_depth === i && prompt.content);
748749