Expand logging for WI and scan states
| @@ -3728,6 +3728,9 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 3728 | 3728 | )].sort((a, b) => a - b); |
| 3729 | 3729 | // Already preset with the first level |
| 3730 | 3730 | let currentRecursionDelayLevel = availableRecursionDelayLevels.shift() ?? 0; |
| 3731 | + if (currentRecursionDelayLevel > 0 && availableRecursionDelayLevels.length) { | |
| 3732 | + console.debug('[WI] Preparing first delayed recursion level', currentRecursionDelayLevel, '. Still delayed:', availableRecursionDelayLevels); | |
| 3733 | + } | |
| 3731 | 3734 | |
| 3732 | 3735 | console.debug(`[WI] --- SEARCHING ENTRIES (on ${sortedEntries.length} entries) ---`); |
| 3733 | 3736 | |
| @@ -3741,7 +3744,8 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 3741 | 3744 | // Track how many times the loop has run. May be useful for debugging. |
| 3742 | 3745 | count++; |
| 3743 | 3746 | |
| 3744 | 3747 | console.debug(`[WI] Loop--- LOOP #${count}. SearchSTART state---`, Object.entries(scan_state).find(x => x[1] === scanState)); |
| 3748 | + console.debug(`[WI] Scan state`, Object.entries(scan_state).find(x => x[1] === scanState)); | |
| 3745 | 3749 | |
| 3746 | 3750 | // Until decided otherwise, we set the loop to stop scanning after this |
| 3747 | 3751 | let nextScanState = scan_state.NONE; |
| @@ -3821,7 +3825,7 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 3821 | 3825 | } |
| 3822 | 3826 | |
| 3823 | 3827 | if (scanState === scan_state.RECURSION && entry.delayUntilRecursion && entry.delayUntilRecursion > currentRecursionDelayLevel && !isSticky) { |
| 3824 | 3828 | log('suppressed by delay until recursion and having alevel', higherentry.delayUntilRecursion, recursion'. levelCurrently', currentRecursionDelayLevel); |
| 3825 | 3829 | continue; |
| 3826 | 3830 | } |
| 3827 | 3831 | |
| @@ -3963,6 +3967,8 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 3963 | 3967 | filterByInclusionGroups(newEntries, allActivatedEntries, buffer, scanState, timedEffects); |
| 3964 | 3968 | |
| 3965 | 3969 | console.debug('[WI] --- PROBABILITY CHECKS ---'); |
| 3970 | + !newEntries.length && console.debug('[WI] No probability checks to do'); | |
| 3971 | + | |
| 3966 | 3972 | for (const entry of newEntries) { |
| 3967 | 3973 | function verifyProbability() { |
| 3968 | 3974 | // If we don't need to roll, it's always true |
| @@ -3998,6 +4004,7 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 3998 | 4004 | newContent += `${entry.content}\n`; |
| 3999 | 4005 | |
| 4000 | 4006 | if ((textToScanTokens + (await getTokenCountAsync(newContent))) >= budget) { |
| 4007 | + console.debug('[WI] --- BUDGET OVERFLOW CHECK ---'); | |
| 4001 | 4008 | if (world_info_overflow_alert) { |
| 4002 | 4009 | console.warn(`[WI] budget of ${budget} reached, stopping after ${allActivatedEntries.size} entries`); |
| 4003 | 4010 | toastr.warning(`World info budget reached after ${allActivatedEntries.size} entries.`, 'World Info'); |
| @@ -4015,23 +4022,31 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 4015 | 4022 | const successfulNewEntries = newEntries.filter(x => !failedProbabilityChecks.has(x)); |
| 4016 | 4023 | const successfulNewEntriesForRecursion = successfulNewEntries.filter(x => !x.preventRecursion); |
| 4017 | 4024 | |
| 4025 | + console.debug(`[WI] --- LOOP #${count} RESULT ---`); | |
| 4018 | 4026 | if (!newEntries.length) { |
| 4019 | 4027 | console.debug('[WI] No new entries activated, stopping.'); |
| 4020 | 4028 | } else if (!successfulNewEntries.length) { |
| 4021 | 4029 | console.debug('[WI] Probability checks failed for all activated entries,. stoppingNo new entries activated.'); |
| 4022 | 4030 | } else { |
| 4023 | 4031 | console.debug(`[WI] Successfully activated ${successfulNewEntries.length} new entries to prompt. ${allActivatedEntries.size} total entries activated.`, successfulNewEntries); |
| 4024 | 4032 | } |
| 4025 | 4033 | |
| 4034 | + function logNextState(...args) { | |
| 4035 | + args.length && console.debug(args.shift(), ...args); | |
| 4036 | + console.debug('[WI] Setting scan state', Object.entries(scan_state).find(x => x[1] === scanState)); | |
| 4037 | + } | |
| 4038 | + | |
| 4026 | 4039 | // After processing and rolling entries is done, see if we should continue with normal recursion |
| 4027 | 4040 | if (world_info_recursive && !token_budget_overflowed && successfulNewEntriesForRecursion.length) { |
| 4028 | 4041 | nextScanState = scan_state.RECURSION; |
| 4042 | + logNextState('[WI] Found', successfulNewEntriesForRecursion.length, 'new entries for recursion'); | |
| 4029 | 4043 | } |
| 4030 | 4044 | |
| 4031 | 4045 | // If we are inside min activations scan, and we have recursive buffer, we should do a recursive scan before increasing the buffer again |
| 4032 | 4046 | // There might be recurse-trigger-able entries that match the buffer, so we need to check that |
| 4033 | 4047 | if (world_info_recursive && !token_budget_overflowed && scanState === scan_state.MIN_ACTIVATIONS && buffer.hasRecurse()) { |
| 4034 | 4048 | nextScanState = scan_state.RECURSION; |
| 4049 | + logNextState('[WI] Min Activations run done, whill will always be followed by a recursive scan'); | |
| 4035 | 4050 | } |
| 4036 | 4051 | |
| 4037 | 4052 | // If scanning is planned to stop, but min activations is set and not satisfied, check if we should continue |
| @@ -4045,8 +4060,8 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 4045 | 4060 | ) || (buffer.getDepth() > chat.length); |
| 4046 | 4061 | |
| 4047 | 4062 | if (!over_max) { |
| 4048 | - console.debug(`[WI] Min activations not reached (${allActivatedEntries.size}/${world_info_min_activations}), advancing depth to ${buffer.getDepth() + 1} and checking again`); | |
| 4049 | 4063 | nextScanState = scan_state.MIN_ACTIVATIONS; // loop |
| 4064 | + logNextState(`[WI] Min activations not reached (${allActivatedEntries.size}/${world_info_min_activations}), advancing depth to ${buffer.getDepth() + 1}, starting another scan`); | |
| 4050 | 4065 | buffer.advanceScan(); |
| 4051 | 4066 | } else { |
| 4052 | 4067 | console.debug(`[WI] Min activations not reached (${allActivatedEntries.size}/${world_info_min_activations}), but reached on of depth. Stopping`); |
| @@ -4057,6 +4072,7 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 4057 | 4072 | if (nextScanState === scan_state.NONE && availableRecursionDelayLevels.length) { |
| 4058 | 4073 | nextScanState = scan_state.RECURSION; |
| 4059 | 4074 | currentRecursionDelayLevel = availableRecursionDelayLevels.shift(); |
| 4075 | + logNextState('[WI] Open delayed recursion levels left. Preparing next delayed recursion level', currentRecursionDelayLevel, '. Still delayed:', availableRecursionDelayLevels); | |
| 4060 | 4076 | } |
| 4061 | 4077 | |
| 4062 | 4078 | // Final check if we should really continue scan, and extend the current WI recurse buffer |
| @@ -4066,6 +4082,8 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) { | ||
| 4066 | 4082 | .map(x => x.content).join('\n'); |
| 4067 | 4083 | buffer.addRecurse(text); |
| 4068 | 4084 | allActivatedText = (text + '\n' + allActivatedText); |
| 4085 | + } else { | |
| 4086 | + logNextState('[WI] Scan done. No new entries to prompt. Stopping.'); | |
| 4069 | 4087 | } |
| 4070 | 4088 | } |
| 4071 | 4089 | |