#2467 Fix min activations for non-recursable entries
| @@ -50,6 +50,24 @@ const world_info_logic = { | ||
| 50 | 50 | AND_ALL: 3, |
| 51 | 51 | }; |
| 52 | 52 | |
| 53 | +/** | |
| 54 | + * @enum {number} Possible states of the WI evaluation | |
| 55 | + */ | |
| 56 | +const scan_state = { | |
| 57 | + /** | |
| 58 | + * The scan will be stopped. | |
| 59 | + */ | |
| 60 | + NONE: 0, | |
| 61 | + /** | |
| 62 | + * The scan is triggered by a recursion step. Initial state. | |
| 63 | + */ | |
| 64 | + RECURSION: 1, | |
| 65 | + /** | |
| 66 | + * The scan is triggered by a min activations depth skew. | |
| 67 | + */ | |
| 68 | + MIN_ACTIVATIONS: 2, | |
| 69 | +}; | |
| 70 | + | |
| 53 | 71 | const WI_ENTRY_EDIT_TEMPLATE = $('#entry_edit_template .world_entry'); |
| 54 | 72 | |
| 55 | 73 | let world_info = {}; |
| @@ -3508,7 +3526,7 @@ async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 3508 | 3526 | } |
| 3509 | 3527 | } |
| 3510 | 3528 | |
| 3511 | 3529 | let needsToScanscanState = truescan_state.RECURSION; |
| 3512 | 3530 | let token_budget_overflowed = false; |
| 3513 | 3531 | let count = 0; |
| 3514 | 3532 | let allActivatedEntries = new Set(); |
| @@ -3532,7 +3550,7 @@ async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 3532 | 3550 | return { worldInfoBefore: '', worldInfoAfter: '', WIDepthEntries: [], EMEntries: [], allActivatedEntries: new Set() }; |
| 3533 | 3551 | } |
| 3534 | 3552 | |
| 3535 | 3553 | while (needsToScanscanState) { |
| 3536 | 3554 | // Track how many times the loop has run |
| 3537 | 3555 | count++; |
| 3538 | 3556 | |
| @@ -3587,7 +3605,12 @@ async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 3587 | 3605 | continue; |
| 3588 | 3606 | } |
| 3589 | 3607 | |
| 3590 | 3608 | if (allActivatedEntries.has(entry) || entry.disable == true || (count > 1 && world_info_recursive && entry.excludeRecursion) || (count == 1 && entry.delayUntilRecursion)) { |
| 3609 | + continue; | |
| 3610 | + } | |
| 3611 | + | |
| 3612 | + // Only use checks for recursion flags if the scan step was activated by recursion | |
| 3613 | + if (scanState === scan_state.RECURSION && ((count > 1 && world_info_recursive && entry.excludeRecursion) || (count == 1 && entry.delayUntilRecursion))) { | |
| 3591 | 3614 | continue; |
| 3592 | 3615 | } |
| 3593 | 3616 | |
| @@ -3665,7 +3688,7 @@ async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 3665 | 3688 | } |
| 3666 | 3689 | } |
| 3667 | 3690 | |
| 3668 | 3691 | needsToScanscanState = world_info_recursive && activatedNow.size > 0 ? scan_state.RECURSION : scan_state.NONE; |
| 3669 | 3692 | const newEntries = [...activatedNow] |
| 3670 | 3693 | .sort((a, b) => sortedEntries.indexOf(a) - sortedEntries.indexOf(b)); |
| 3671 | 3694 | let newContent = ''; |
| @@ -3697,7 +3720,7 @@ async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 3697 | 3720 | console.log('Alerting'); |
| 3698 | 3721 | toastr.warning(`World info budget reached after ${allActivatedEntries.size} entries.`, 'World Info'); |
| 3699 | 3722 | } |
| 3700 | 3723 | needsToScanscanState = falsescan_state.NONE; |
| 3701 | 3724 | token_budget_overflowed = true; |
| 3702 | 3725 | break; |
| 3703 | 3726 | } |
| @@ -3710,15 +3733,15 @@ async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 3710 | 3733 | |
| 3711 | 3734 | if ((probabilityChecksAfter - probabilityChecksBefore) === activatedNow.size) { |
| 3712 | 3735 | console.debug('WI probability checks failed for all activated entries, stopping'); |
| 3713 | 3736 | needsToScanscanState = falsescan_state.NONE; |
| 3714 | 3737 | } |
| 3715 | 3738 | |
| 3716 | 3739 | if (newEntries.length === 0) { |
| 3717 | 3740 | console.debug('No new entries activated, stopping'); |
| 3718 | 3741 | needsToScanscanState = falsescan_state.NONE; |
| 3719 | 3742 | } |
| 3720 | 3743 | |
| 3721 | 3744 | if (needsToScanscanState) { |
| 3722 | 3745 | const text = newEntries |
| 3723 | 3746 | .filter(x => !failedProbabilityChecks.has(x)) |
| 3724 | 3747 | .filter(x => !x.preventRecursion) |
| @@ -3728,7 +3751,7 @@ async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 3728 | 3751 | } |
| 3729 | 3752 | |
| 3730 | 3753 | // world_info_min_activations |
| 3731 | 3754 | if (!needsToScanscanState && !token_budget_overflowed) { |
| 3732 | 3755 | if (world_info_min_activations > 0 && (allActivatedEntries.size < world_info_min_activations)) { |
| 3733 | 3756 | let over_max = ( |
| 3734 | 3757 | world_info_min_activations_depth_max > 0 && |
| @@ -3736,7 +3759,7 @@ async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 3736 | 3759 | ) || (buffer.getDepth() > chat.length); |
| 3737 | 3760 | |
| 3738 | 3761 | if (!over_max) { |
| 3739 | 3762 | needsToScanscanState = truescan_state.MIN_ACTIVATIONS; // loop |
| 3740 | 3763 | buffer.advanceScanPosition(); |
| 3741 | 3764 | } |
| 3742 | 3765 | } |