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