| 3836 | } | 3837 | } |
| 3837 | | 3838 | |
| 3838 | const successfulNewEntries = newEntries.filter(x => !failedProbabilityChecks.has(x)); | 3839 | const successfulNewEntries = newEntries.filter(x => !failedProbabilityChecks.has(x)); |
| | 3840 | const successfulNewEntriesForRecursion = successfulNewEntries.filter(x => !x.preventRecursion); |
| 3839 | | 3841 | |
| 3840 | if (!newEntries.length) { | 3842 | if (!newEntries.length) { |
| 3841 | console.debug('[WI] No new entries activated, stopping'); | 3843 | console.debug('[WI] No new entries activated, stopping'); |
| 3842 | scanState = scan_state.NONE; | 3844 | } else if (!successfulNewEntries.length) { |
| 3843 | } | | |
| 3844 | | | |
| 3845 | if (newEntries.length && !successfulNewEntries.length) { | | |
| 3846 | console.debug('[WI] Probability checks failed for all activated entries, stopping'); | 3845 | console.debug('[WI] Probability checks failed for all activated entries, stopping'); |
| 3847 | scanState = scan_state.NONE; | 3846 | } else { |
| 3848 | } | 3847 | console.debug(`[WI] Sucessfully activated ${successfulNewEntries.length} new entries to prompt. ${allActivatedEntries.size} total entries activated.`, successfulNewEntries); |
| 3849 | | | |
| 3850 | if (scanState) { | | |
| 3851 | const text = successfulNewEntries | | |
| 3852 | .filter(x => !x.preventRecursion) | | |
| 3853 | .map(x => x.content).join('\n'); | | |
| 3854 | buffer.addRecurse(text); | | |
| 3855 | allActivatedText = (text + '\n' + allActivatedText); | | |
| 3856 | } | 3848 | } |
| 3857 | | 3849 | |
| 3858 | if (successfulNewEntries.length) { | 3850 | // After processing and rolling entries is done, see if we should continue with recursion |
| 3859 | console.debug(`[WI] Sucessfully activated ${successfulNewEntries.length} new entries to prompt. ${allActivatedEntries.size} total entries activated.`, successfulNewEntries); | 3851 | if (world_info_recursive && !token_budget_overflowed && successfulNewEntriesForRecursion.length) { |
| | 3852 | nextScanState = scan_state.RECURSION; |
| 3860 | } | 3853 | } |
| 3861 | | 3854 | |
| 3862 | // world_info_min_activations | 3855 | // If scanning is planned to stop, but min activations is set and not satisfied, check if we should continue |
| 3863 | if (!scanState && !token_budget_overflowed) { | 3856 | const minActivationsNotSatisfied = world_info_min_activations > 0 && (allActivatedEntries.size < world_info_min_activations); |
| 3864 | if (world_info_min_activations > 0 && (allActivatedEntries.size < world_info_min_activations)) { | 3857 | if (!nextScanState && !token_budget_overflowed && minActivationsNotSatisfied) { |
| 3865 | console.debug('[WI] --- MIN ACTIVATIONS CHECK ---'); | 3858 | console.debug('[WI] --- MIN ACTIVATIONS CHECK ---'); |
| 3866 | | 3859 | |
| 3867 | let over_max = ( | 3860 | let over_max = ( |
| 3868 | world_info_min_activations_depth_max > 0 && | 3861 | world_info_min_activations_depth_max > 0 && |
| 3869 | buffer.getDepth() > world_info_min_activations_depth_max | 3862 | buffer.getDepth() > world_info_min_activations_depth_max |
| 3870 | ) || (buffer.getDepth() > chat.length); | 3863 | ) || (buffer.getDepth() > chat.length); |
| 3871 | | 3864 | |
| 3872 | if (!over_max) { | 3865 | if (!over_max) { |
| 3873 | console.debug(`[WI] Min activations not reached (${allActivatedEntries.size}/${world_info_min_activations}), advancing depth to ${buffer.getDepth() + 1} and checking again`); | 3866 | console.debug(`[WI] Min activations not reached (${allActivatedEntries.size}/${world_info_min_activations}), advancing depth to ${buffer.getDepth() + 1} and checking again`); |
| 3874 | scanState = scan_state.MIN_ACTIVATIONS; // loop | 3867 | nextScanState = scan_state.MIN_ACTIVATIONS; // loop |
| 3875 | buffer.advanceScanPosition(); | 3868 | buffer.advanceScanPosition(); |
| 3876 | } else { | 3869 | } else { |
| 3877 | console.debug(`[WI] Min activations not reached (${allActivatedEntries.size}/${world_info_min_activations}), but reached on of depth. Stopping`); | 3870 | console.debug(`[WI] Min activations not reached (${allActivatedEntries.size}/${world_info_min_activations}), but reached on of depth. Stopping`); |
| 3878 | } | | |
| 3879 | } | 3871 | } |
| 3880 | } | 3872 | } |
| | 3873 | |
| | 3874 | // Final check if we should really continue scan, and extend the current WI recurse buffer |
| | 3875 | scanState = nextScanState; |
| | 3876 | if (scanState) { |
| | 3877 | const text = successfulNewEntriesForRecursion |
| | 3878 | .map(x => x.content).join('\n'); |
| | 3879 | buffer.addRecurse(text); |
| | 3880 | allActivatedText = (text + '\n' + allActivatedText); |
| | 3881 | } |
| 3881 | } | 3882 | } |
| 3882 | | 3883 | |
| 3883 | console.debug('[WI] --- BUILDING PROMPT ---'); | 3884 | console.debug('[WI] --- BUILDING PROMPT ---'); |