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>

a276dbdd4437fb5916ecf163295800ec29893f24

honey-tree <kalakanlogs@proton.me>

Signed
2 files changed, +38 -1Showing whitespace changes
public/index.html+9 -0
@@ -3622,6 +3622,7 @@
36223622 <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.">
36233623 <small>
36243624 <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>
36253626 </small>
36263627 <input class="neo-range-slider" type="range" id="world_info_min_activations" name="world_info_min_activations" min="0" max="100" step="1">
36273628 <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 @@
36353636 <input class="neo-range-slider" type="range" id="world_info_min_activations_depth_max" name="volume" min="0" max="100" step="1">
36363637 <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">
36373638 </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&#10;(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>
36383647
36393648 <div class="alignitemscenter flex-container flexFlowColumn flexGrow flexShrink flexBasis48p">
36403649 <small data-i18n="Insertion Strategy">
public/scripts/world-info.js+29 -1
@@ -73,6 +73,7 @@ export let world_info_match_whole_words = false;
7373export let world_info_use_group_scoring = false;
7474export let world_info_character_strategy = world_info_insertion_strategy.character_first;
7575export let world_info_budget_cap = 0;
76+export let world_info_max_recursion_steps = 0;
7677const saveWorldDebounced = debounce(async (name, data) => await _save(name, data), debounce_timeout.relaxed);
7778const saveSettingsDebounced = debounce(() => {
7879 Object.assign(world_info, { globalSelect: selected_world_info });
@@ -710,6 +711,7 @@ export function getWorldInfoSettings() {
710711 world_info_character_strategy,
711712 world_info_budget_cap,
712713 world_info_use_group_scoring,
714+ world_info_max_recursion_steps,
713715 };
714716}
715717
@@ -796,6 +798,8 @@ export function setWorldInfoSettings(settings, data) {
796798 world_info_budget_cap = Number(settings.world_info_budget_cap);
797799 if (settings.world_info_use_group_scoring !== undefined)
798800 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);
799803
800804 // Migrate old settings
801805 if (world_info_budget > 100) {
@@ -844,6 +848,9 @@ export function setWorldInfoSettings(settings, data) {
844848 $('#world_info_budget_cap').val(world_info_budget_cap);
845849 $('#world_info_budget_cap_counter').val(world_info_budget_cap);
846850
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+
847854 world_names = data.world_names?.length ? data.world_names : [];
848855
849856 // Add to existing selected WI if it exists
@@ -3723,6 +3730,12 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
37233730 console.debug(`[WI] --- SEARCHING ENTRIES (on ${sortedEntries.length} entries) ---`);
37243731
37253732 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+
37263739 // Track how many times the loop has run. May be useful for debugging.
37273740 count++;
37283741
@@ -4762,8 +4775,13 @@ jQuery(() => {
47624775
47634776 $('#world_info_min_activations').on('input', function () {
47644777 world_info_min_activations = Number($(this).val());
47654778 $('#world_info_min_activations_counter').val($(this).val()world_info_min_activations);
4779+
4780+ if (world_info_min_activations !== 0) {
4781+ $('#world_info_max_recursion_steps').val(0).trigger('input');
4782+ } else {
47664783 saveSettings();
4784+ }
47674785 });
47684786
47694787 $('#world_info_min_activations_depth_max').on('input', function () {
@@ -4819,6 +4837,16 @@ jQuery(() => {
48194837 saveSettings();
48204838 });
48214839
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+
48224850 $('#world_button').on('click', async function (event) {
48234851 const chid = $('#set_character_world').data('chid');
48244852