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 @@
5142 <div id="persona_depth_position_settings" class="flex-container">5142 <div id="persona_depth_position_settings" class="flex-container">
5143 <div class="flex1">5143 <div class="flex1">
5144 <label for="persona_depth_value" data-i18n="Depth:">Depth:</label>5144 <label for="persona_depth_value" data-i18n="Depth:">Depth:</label>
5145 <input id="persona_depth_value" class="text_pole" type="number" min="0" max="999" step="1">5145 <input id="persona_depth_value" class="text_pole" type="number" min="0" max="9999" step="1">
5146 </div>5146 </div>
5147 <div class="flex1">5147 <div class="flex1">
5148 <label for="persona_depth_role" data-i18n="Role:">Role:</label>5148 <label for="persona_depth_role" data-i18n="Role:">Role:</label>
@@ -5795,7 +5795,7 @@
5795 @ Depth5795 @ Depth
5796 </span>5796 </span>
5797 </h4>5797 </h4>
5798 <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" />5798 <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" />
5799 <h4>5799 <h4>
5800 <span data-i18n="Role">5800 <span data-i18n="Role">
5801 Role5801 Role
@@ -6016,11 +6016,11 @@
6016 </div>6016 </div>
6017 <div class="world_entry_form_control wi-enter-footer-text flex-container flexNoGap">6017 <div class="world_entry_form_control wi-enter-footer-text flex-container flexNoGap">
6018 <label for="depth" class="WIEntryHeaderTitleMobile" data-i18n="Depth:">Depth:</label>6018 <label for="depth" class="WIEntryHeaderTitleMobile" data-i18n="Depth:">Depth:</label>
6019 <input title="Depth" class="text_pole wideMax100px margin0" type="number" name="depth" data-i18n="[title]Depth" placeholder="" min="0" max="999" />6019 <input title="Depth" class="text_pole wideMax100px margin0" type="number" name="depth" data-i18n="[title]Depth" placeholder="" min="0" max="9999" />
6020 </div>6020 </div>
6021 <div class="world_entry_form_control wi-enter-footer-text flex-container flexNoGap">6021 <div class="world_entry_form_control wi-enter-footer-text flex-container flexNoGap">
6022 <label for="order" class="WIEntryHeaderTitleMobile" data-i18n="Order:">Order:</label>6022 <label for="order" class="WIEntryHeaderTitleMobile" data-i18n="Order:">Order:</label>
6023 <input title="Order" data-i18n="[title]Order" class="text_pole wideMax100px margin0" type="number" name="order" placeholder="" min="0" max="999" />6023 <input title="Order" data-i18n="[title]Order" class="text_pole wideMax100px margin0" type="number" name="order" placeholder="" min="0" max="9999" />
6024 </div>6024 </div>
6025 <div class="world_entry_form_control wi-enter-footer-text flex-container flexNoGap probabilityContainer">6025 <div class="world_entry_form_control wi-enter-footer-text flex-container flexNoGap probabilityContainer">
6026 <label for="order" class="WIEntryHeaderTitleMobile" data-i18n="Trigger %:">Trigger %:</label>6026 <label for="order" class="WIEntryHeaderTitleMobile" data-i18n="Trigger %:">Trigger %:</label>
@@ -6382,7 +6382,7 @@
6382 <span data-i18n="prompt_manager_depth">Depth</span>6382 <span data-i18n="prompt_manager_depth">Depth</span>
6383 </label>6383 </label>
6384 <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>6384 <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>
6385 <input id="completion_prompt_manager_popup_entry_form_injection_depth" class="text_pole" type="number" name="injection_depth" min="0" max="999" value="4" />6385 <input id="completion_prompt_manager_popup_entry_form_injection_depth" class="text_pole" type="number" name="injection_depth" min="0" max="9999" value="4" />
6386 </div>6386 </div>
6387 </div>6387 </div>
6388 <div class="completion_prompt_manager_popup_entry_form_control">6388 <div class="completion_prompt_manager_popup_entry_form_control">
@@ -6742,7 +6742,7 @@
6742 <label class="checkbox_label alignItemsCenter" for="extension_floating_position_depth">6742 <label class="checkbox_label alignItemsCenter" for="extension_floating_position_depth">
6743 <input type="radio" id="extension_floating_position_depth" name="extension_floating_position" value="1" />6743 <input type="radio" id="extension_floating_position_depth" name="extension_floating_position" value="1" />
6744 <span data-i18n="In-chat @ Depth">In-chat @ Depth</span>6744 <span data-i18n="In-chat @ Depth">In-chat @ Depth</span>
6745 <input id="extension_floating_depth" class="text_pole textarea_compact widthNatural" type="number" min="0" max="999" />6745 <input id="extension_floating_depth" class="text_pole textarea_compact widthNatural" type="number" min="0" max="9999" />
6746 <span data-i18n="as">as</span>6746 <span data-i18n="as">as</span>
6747 <select id="extension_floating_role" class="text_pole widthNatural">6747 <select id="extension_floating_role" class="text_pole widthNatural">
6748 <option data-i18n="System" value="0">System</option>6748 <option data-i18n="System" value="0">System</option>
@@ -6757,7 +6757,7 @@
6757 <span data-i18n="Insertion Frequency">Insertion Frequency</span>6757 <span data-i18n="Insertion Frequency">Insertion Frequency</span>
6758 <small data-i18n="(0 = Disable, 1 = Always)">(0 = Disable, 1 = Always)</small>6758 <small data-i18n="(0 = Disable, 1 = Always)">(0 = Disable, 1 = Always)</small>
6759 </label>6759 </label>
6760 <input id="extension_floating_interval" class="text_pole widthUnset" type="number" min="0" max="999" />6760 <input id="extension_floating_interval" class="text_pole widthUnset" type="number" min="0" max="9999" />
6761 </div>6761 </div>
6762 <br>6762 <br>
6763 <span><span data-i18n="User inputs until next insertion:">User inputs until next insertion:</span> <span id="extension_floating_counter">(disabled)</span></span>6763 <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 @@
6827 <label class="checkbox_label alignItemsCenter" for="extension_default_position_depth">6827 <label class="checkbox_label alignItemsCenter" for="extension_default_position_depth">
6828 <input type="radio" id="extension_default_position_depth" name="extension_default_position" value="1" />6828 <input type="radio" id="extension_default_position_depth" name="extension_default_position" value="1" />
6829 <span data-i18n="In-chat @ Depth">In-chat @ Depth</span>6829 <span data-i18n="In-chat @ Depth">In-chat @ Depth</span>
6830 <input id="extension_default_depth" class="text_pole textarea_compact widthNatural" type="number" min="0" max="999" />6830 <input id="extension_default_depth" class="text_pole textarea_compact widthNatural" type="number" min="0" max="9999" />
6831 <span data-i18n="as">as</span>6831 <span data-i18n="as">as</span>
6832 <select id="extension_default_role" class="text_pole widthNatural">6832 <select id="extension_default_role" class="text_pole widthNatural">
6833 <option data-i18n="System" value="0">System</option>6833 <option data-i18n="System" value="0">System</option>
@@ -6841,7 +6841,7 @@
6841 <span data-i18n="Insertion Frequency">Insertion Frequency</span>6841 <span data-i18n="Insertion Frequency">Insertion Frequency</span>
6842 <small data-i18n="(0 = Disable, 1 = Always)">(0 = Disable, 1 = Always)</small>6842 <small data-i18n="(0 = Disable, 1 = Always)">(0 = Disable, 1 = Always)</small>
6843 </label>6843 </label>
6844 <input id="extension_default_interval" class="text_pole widthUnset" type="number" min="0" max="999" />6844 <input id="extension_default_interval" class="text_pole widthUnset" type="number" min="0" max="9999" />
6845 </div>6845 </div>
6846 </div>6846 </div>
6847 </div>6847 </div>
public/script.js+14 -2
@@ -651,7 +651,7 @@ export const extension_prompt_roles = {
651 ASSISTANT: 2,651 ASSISTANT: 2,
652};652};
653653
654export const MAX_INJECTION_DEPTH = 1000;654export const MAX_INJECTION_DEPTH = 10000;
655655
656const SAFETY_CHAT = [656const SAFETY_CHAT = [
657 {657 {
@@ -3047,6 +3047,17 @@ export async function getExtensionPromptByName(moduleName) {
3047}3047}
30483048
3049/**3049/**
3050 * Gets the maximum depth of extension prompts.
3051 * @returns {number} Maximum depth of extension prompts
3052 */
3053export 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/**
3050 * Returns the extension prompt for the given position, depth, and role.3061 * Returns the extension prompt for the given position, depth, and role.
3051 * If multiple prompts are found, they are joined with a separator.3062 * If multiple prompts are found, they are joined with a separator.
3052 * @param {number} [position] Position of the prompt3063 * @param {number} [position] Position of the prompt
@@ -5099,7 +5110,8 @@ async function doChatInject(messages, isContinue) {
5099 let totalInsertedMessages = 0;5110 let totalInsertedMessages = 0;
5100 messages.reverse();5111 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++) {
5103 // Order of priority (most important go lower)5115 // Order of priority (most important go lower)
5104 const roles = [extension_prompt_roles.SYSTEM, extension_prompt_roles.USER, extension_prompt_roles.ASSISTANT];5116 const roles = [extension_prompt_roles.SYSTEM, extension_prompt_roles.USER, extension_prompt_roles.ASSISTANT];
5105 const names = {5117 const names = {
public/scripts/extensions/memory/settings.html+1 -1
@@ -132,7 +132,7 @@
132 </label>132 </label>
133 <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.">133 <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.">
134 <input type="radio" name="memory_position" value="1" />134 <input type="radio" name="memory_position" value="1" />
135 <span data-i18n="In-chat @ Depth">In-chat @ Depth</span> <input id="memory_depth" class="text_pole widthUnset" type="number" min="0" max="999" />135 <span data-i18n="In-chat @ Depth">In-chat @ Depth</span> <input id="memory_depth" class="text_pole widthUnset" type="number" min="0" max="9999" />
136 <span data-i18n="as">as</span>136 <span data-i18n="as">as</span>
137 <select id="memory_role" class="text_pole widthNatural">137 <select id="memory_role" class="text_pole widthNatural">
138 <option value="0" data-i18n="System">System</option>138 <option value="0" data-i18n="System">System</option>
public/scripts/extensions/regex/editor.html+2 -2
@@ -113,14 +113,14 @@
113 <span data-i18n="Min Depth">Min Depth</span>113 <span data-i18n="Min Depth">Min Depth</span>
114 <span class="fa-solid fa-circle-question note-link-span"></span>114 <span class="fa-solid fa-circle-question note-link-span"></span>
115 </small>115 </small>
116 <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" />116 <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" />
117 </div>117 </div>
118 <div class="flex1 flex-container flexNoGap">118 <div class="flex1 flex-container flexNoGap">
119 <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.">119 <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.">
120 <span data-i18n="Max Depth">Max Depth</span>120 <span data-i18n="Max Depth">Max Depth</span>
121 <span class="fa-solid fa-circle-question note-link-span"></span>121 <span class="fa-solid fa-circle-question note-link-span"></span>
122 </small>122 </small>
123 <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" />123 <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" />
124 </div>124 </div>
125 </div>125 </div>
126 </div>126 </div>
public/scripts/extensions/vectors/settings.html+2 -2
@@ -310,7 +310,7 @@
310 <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.">310 <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.">
311 <input type="radio" name="vectors_file_position_db" value="1" />311 <input type="radio" name="vectors_file_position_db" value="1" />
312 <span data-i18n="In-chat @ Depth">In-chat @ Depth</span>312 <span data-i18n="In-chat @ Depth">In-chat @ Depth</span>
313 <input id="vectors_file_depth_db" class="text_pole widthUnset" type="number" min="0" max="999" />313 <input id="vectors_file_depth_db" class="text_pole widthUnset" type="number" min="0" max="9999" />
314 <span>as</span>314 <span>as</span>
315 <select id="vectors_file_depth_role_db" class="text_pole widthNatural">315 <select id="vectors_file_depth_role_db" class="text_pole widthNatural">
316 <option value="0" data-i18n="System">System</option>316 <option value="0" data-i18n="System">System</option>
@@ -362,7 +362,7 @@
362 <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.">362 <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.">
363 <input type="radio" name="vectors_position" value="1" />363 <input type="radio" name="vectors_position" value="1" />
364 <span data-i18n="In-chat @ Depth">In-chat @ Depth </span>364 <span data-i18n="In-chat @ Depth">In-chat @ Depth </span>
365 <input id="vectors_depth" class="text_pole widthUnset" type="number" min="0" max="999" />365 <input id="vectors_depth" class="text_pole widthUnset" type="number" min="0" max="9999" />
366 </label>366 </label>
367 </div>367 </div>
368 <div class="flex-container">368 <div class="flex-container">
public/scripts/openai.js+3 -2
@@ -15,12 +15,12 @@ import {
15 extension_prompt_types,15 extension_prompt_types,
16 Generate,16 Generate,
17 getExtensionPrompt,17 getExtensionPrompt,
18 getExtensionPromptMaxDepth,
18 getNextMessageId,19 getNextMessageId,
19 getRequestHeaders,20 getRequestHeaders,
20 getStoppingStrings,21 getStoppingStrings,
21 is_send_press,22 is_send_press,
22 main_api,23 main_api,
23 MAX_INJECTION_DEPTH,
24 name1,24 name1,
25 name2,25 name2,
26 replaceItemizedPromptText,26 replaceItemizedPromptText,
@@ -742,7 +742,8 @@ async function populationInjectionPrompts(prompts, messages) {
742 'assistant': extension_prompt_roles.ASSISTANT,742 'assistant': extension_prompt_roles.ASSISTANT,
743 };743 };
744744
745 for (let i = 0; i <= MAX_INJECTION_DEPTH; i++) {745 const maxDepth = getExtensionPromptMaxDepth();
746 for (let i = 0; i <= maxDepth; i++) {
746 // Get prompts for current depth747 // Get prompts for current depth
747 const depthPrompts = prompts.filter(prompt => prompt.injection_depth === i && prompt.content);748 const depthPrompts = prompts.filter(prompt => prompt.injection_depth === i && prompt.content);
748749