Implements max recursion depth for lorebooks (#2698) * Include slider for Max Recursion Depth * Implement Behavior for Max Recursion Depth * Title message correction * Disabling min activations when max recursion depth is disabled and vice versa * Feature renamed to Max Recursion Steps * Added warnings that min activations and max recursion steps disable each other * Revert "Added warnings that min activations and max recursion steps disable each other" This reverts commit 8c7efd09c5d126372edd529f9537611fec4b59df. * Revert "Feature renamed to Max Recursion Steps" This reverts commit f043fe6b60693339a8270f148a7cb98f252ea592. * Revert "Disabling min activations when max recursion depth is disabled and vice versa" This reverts commit a3a28874bf16a8ee4162c2036efbdae736b076b5. * Renames the feature to Max Recursion Steps and disables it when Min Activations are enabled * Combine info-warnings, log stop condition --------- Co-authored-by: Your Name <you@example.com> Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
Signed| @@ -3622,6 +3622,7 @@ | ||
| 3622 | 3622 | <div class="alignitemscenter flex-container flexFlowColumn flexGrow flexShrink gap0 flexBasis48p" title="Scan chronologically until reached min entries or token budget." data-i18n="[title]Scan chronologically until reached min entries or token budget."> |
| 3623 | 3623 | <small> |
| 3624 | 3624 | <span data-i18n="Min Activations">Min Activations</span> |
| 3625 | + <div class="fa-solid fa-triangle-exclamation opacity50p" data-i18n="[title](disabled when max recursion steps are used)" title="(disabled when max recursion steps are used)"></div> | |
| 3625 | 3626 | </small> |
| 3626 | 3627 | <input class="neo-range-slider" type="range" id="world_info_min_activations" name="world_info_min_activations" min="0" max="100" step="1"> |
| 3627 | 3628 | <input class="neo-range-input" type="number" min="0" max="100" step="1" data-for="world_info_min_activations" id="world_info_min_activations_counter"> |
| @@ -3635,6 +3636,14 @@ | ||
| 3635 | 3636 | <input class="neo-range-slider" type="range" id="world_info_min_activations_depth_max" name="volume" min="0" max="100" step="1"> |
| 3636 | 3637 | <input class="neo-range-input" type="number" min="0" max="100" step="1" data-for="world_info_min_activations_depth_max" id="world_info_min_activations_depth_max_counter"> |
| 3637 | 3638 | </div> |
| 3639 | + <div class="alignitemscenter flex-container flexFlowColumn flexGrow flexShrink gap0 flexBasis48p" title="Cap the number of entry activation recursions" data-i18n="[title]Cap the number of entry activation recursions"> | |
| 3640 | + <small> | |
| 3641 | + <span data-i18n="Max Recursion Steps">Max Recursion Steps</span> | |
| 3642 | + <div class="fa-solid fa-triangle-exclamation opacity50p" data-i18n="[title]0 = unlimited, 1 = scans once and doesn't recurse, 2 = scans once and recurses once, etc\n(disabled when min activations are used)" title="0 = unlimited, 1 = scans once and doesn't recurse, 2 = scans once and recurses once, etc (disabled when min activations are used)"></div> | |
| 3643 | + </small> | |
| 3644 | + <input class="neo-range-slider" type="range" id="world_info_max_recursion_steps" name="world_info_max_recursion_steps" min="0" max="10" step="1"> | |
| 3645 | + <input class="neo-range-input" type="number" min="0" max="10" step="1" data-for="world_info_max_recursion_steps" id="world_info_max_recursion_steps_counter"> | |
| 3646 | + </div> | |
| 3638 | 3647 | |
| 3639 | 3648 | <div class="alignitemscenter flex-container flexFlowColumn flexGrow flexShrink flexBasis48p"> |
| 3640 | 3649 | <small data-i18n="Insertion Strategy"> |
| @@ -73,6 +73,7 @@ export let world_info_match_whole_words = false; | ||
| 73 | 73 | export let world_info_use_group_scoring = false; |
| 74 | 74 | export let world_info_character_strategy = world_info_insertion_strategy.character_first; |
| 75 | 75 | export let world_info_budget_cap = 0; |
| 76 | +export let world_info_max_recursion_steps = 0; | |
| 76 | 77 | const saveWorldDebounced = debounce(async (name, data) => await _save(name, data), debounce_timeout.relaxed); |
| 77 | 78 | const saveSettingsDebounced = debounce(() => { |
| 78 | 79 | Object.assign(world_info, { globalSelect: selected_world_info }); |
| @@ -710,6 +711,7 @@ export function getWorldInfoSettings() { | ||
| 710 | 711 | world_info_character_strategy, |
| 711 | 712 | world_info_budget_cap, |
| 712 | 713 | world_info_use_group_scoring, |
| 714 | + world_info_max_recursion_steps, | |
| 713 | 715 | }; |
| 714 | 716 | } |
| 715 | 717 | |
| @@ -796,6 +798,8 @@ export function setWorldInfoSettings(settings, data) { | ||
| 796 | 798 | world_info_budget_cap = Number(settings.world_info_budget_cap); |
| 797 | 799 | if (settings.world_info_use_group_scoring !== undefined) |
| 798 | 800 | world_info_use_group_scoring = Boolean(settings.world_info_use_group_scoring); |
| 801 | + if (settings.world_info_max_recursion_steps !== undefined) | |
| 802 | + world_info_max_recursion_steps = Number(settings.world_info_max_recursion_steps); | |
| 799 | 803 | |
| 800 | 804 | // Migrate old settings |
| 801 | 805 | if (world_info_budget > 100) { |
| @@ -844,6 +848,9 @@ export function setWorldInfoSettings(settings, data) { | ||
| 844 | 848 | $('#world_info_budget_cap').val(world_info_budget_cap); |
| 845 | 849 | $('#world_info_budget_cap_counter').val(world_info_budget_cap); |
| 846 | 850 | |
| 851 | + $('#world_info_max_recursion_steps').val(world_info_max_recursion_steps); | |
| 852 | + $('#world_info_max_recursion_steps_counter').val(world_info_max_recursion_steps); | |
| 853 | + | |
| 847 | 854 | world_names = data.world_names?.length ? data.world_names : []; |
| 848 | 855 | |
| 849 | 856 | // Add to existing selected WI if it exists |
| @@ -3723,6 +3730,12 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 3723 | 3730 | console.debug(`[WI] --- SEARCHING ENTRIES (on ${sortedEntries.length} entries) ---`); |
| 3724 | 3731 | |
| 3725 | 3732 | while (scanState) { |
| 3733 | + //if world_info_max_recursion_steps is non-zero min activations are disabled, and vice versa | |
| 3734 | + if (world_info_max_recursion_steps && world_info_max_recursion_steps <= count) { | |
| 3735 | + console.debug('[WI] Search stopped by reaching max recursion steps', world_info_max_recursion_steps); | |
| 3736 | + break; | |
| 3737 | + } | |
| 3738 | + | |
| 3726 | 3739 | // Track how many times the loop has run. May be useful for debugging. |
| 3727 | 3740 | count++; |
| 3728 | 3741 | |
| @@ -4762,8 +4775,13 @@ jQuery(() => { | ||
| 4762 | 4775 | |
| 4763 | 4776 | $('#world_info_min_activations').on('input', function () { |
| 4764 | 4777 | world_info_min_activations = Number($(this).val()); |
| 4765 | 4778 | $('#world_info_min_activations_counter').val($(this).val()world_info_min_activations); |
| 4766 | - saveSettings(); | |
| 4779 | + | |
| 4780 | + if (world_info_min_activations !== 0) { | |
| 4781 | + $('#world_info_max_recursion_steps').val(0).trigger('input'); | |
| 4782 | + } else { | |
| 4783 | + saveSettings(); | |
| 4784 | + } | |
| 4767 | 4785 | }); |
| 4768 | 4786 | |
| 4769 | 4787 | $('#world_info_min_activations_depth_max').on('input', function () { |
| @@ -4819,6 +4837,16 @@ jQuery(() => { | ||
| 4819 | 4837 | saveSettings(); |
| 4820 | 4838 | }); |
| 4821 | 4839 | |
| 4840 | + $('#world_info_max_recursion_steps').on('input', function () { | |
| 4841 | + world_info_max_recursion_steps = Number($(this).val()); | |
| 4842 | + $('#world_info_max_recursion_steps_counter').val(world_info_max_recursion_steps); | |
| 4843 | + if (world_info_max_recursion_steps !== 0) { | |
| 4844 | + $('#world_info_min_activations').val(0).trigger('input'); | |
| 4845 | + } else { | |
| 4846 | + saveSettings(); | |
| 4847 | + } | |
| 4848 | + }); | |
| 4849 | + | |
| 4822 | 4850 | $('#world_button').on('click', async function (event) { |
| 4823 | 4851 | const chid = $('#set_character_world').data('chid'); |
| 4824 | 4852 | |