Expand logging for WI and scan states

413f6a03793c83fa1f80d1f46e7e27738766f457

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +23 -5Showing whitespace changes
public/scripts/world-info.js+23 -5
@@ -3728,6 +3728,9 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
3728 )].sort((a, b) => a - b);3728 )].sort((a, b) => a - b);
3729 // Already preset with the first level3729 // Already preset with the first level
3730 let currentRecursionDelayLevel = availableRecursionDelayLevels.shift() ?? 0;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 }
37313734
3732 console.debug(`[WI] --- SEARCHING ENTRIES (on ${sortedEntries.length} entries) ---`);3735 console.debug(`[WI] --- SEARCHING ENTRIES (on ${sortedEntries.length} entries) ---`);
37333736
@@ -3741,7 +3744,8 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
3741 // Track how many times the loop has run. May be useful for debugging.3744 // Track how many times the loop has run. May be useful for debugging.
3742 count++;3745 count++;
37433746
3744 console.debug(`[WI] Loop #${count}. Search state`, Object.entries(scan_state).find(x => x[1] === scanState));3747 console.debug(`[WI] --- LOOP #${count} START ---`);
3748 console.debug(`[WI] Scan state`, Object.entries(scan_state).find(x => x[1] === scanState));
37453749
3746 // Until decided otherwise, we set the loop to stop scanning after this3750 // Until decided otherwise, we set the loop to stop scanning after this
3747 let nextScanState = scan_state.NONE;3751 let nextScanState = scan_state.NONE;
@@ -3821,7 +3825,7 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
3821 }3825 }
38223826
3823 if (scanState === scan_state.RECURSION && entry.delayUntilRecursion && entry.delayUntilRecursion > currentRecursionDelayLevel && !isSticky) {3827 if (scanState === scan_state.RECURSION && entry.delayUntilRecursion && entry.delayUntilRecursion > currentRecursionDelayLevel && !isSticky) {
3824 log('suppressed by delay until recursion and having a higher recursion level');3828 log('suppressed by delay until recursion level', entry.delayUntilRecursion, '. Currently', currentRecursionDelayLevel);
3825 continue;3829 continue;
3826 }3830 }
38273831
@@ -3963,6 +3967,8 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
3963 filterByInclusionGroups(newEntries, allActivatedEntries, buffer, scanState, timedEffects);3967 filterByInclusionGroups(newEntries, allActivatedEntries, buffer, scanState, timedEffects);
39643968
3965 console.debug('[WI] --- PROBABILITY CHECKS ---');3969 console.debug('[WI] --- PROBABILITY CHECKS ---');
3970 !newEntries.length && console.debug('[WI] No probability checks to do');
3971
3966 for (const entry of newEntries) {3972 for (const entry of newEntries) {
3967 function verifyProbability() {3973 function verifyProbability() {
3968 // If we don't need to roll, it's always true3974 // If we don't need to roll, it's always true
@@ -3998,6 +4004,7 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
3998 newContent += `${entry.content}\n`;4004 newContent += `${entry.content}\n`;
39994005
4000 if ((textToScanTokens + (await getTokenCountAsync(newContent))) >= budget) {4006 if ((textToScanTokens + (await getTokenCountAsync(newContent))) >= budget) {
4007 console.debug('[WI] --- BUDGET OVERFLOW CHECK ---');
4001 if (world_info_overflow_alert) {4008 if (world_info_overflow_alert) {
4002 console.warn(`[WI] budget of ${budget} reached, stopping after ${allActivatedEntries.size} entries`);4009 console.warn(`[WI] budget of ${budget} reached, stopping after ${allActivatedEntries.size} entries`);
4003 toastr.warning(`World info budget reached after ${allActivatedEntries.size} entries.`, 'World Info');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 const successfulNewEntries = newEntries.filter(x => !failedProbabilityChecks.has(x));4022 const successfulNewEntries = newEntries.filter(x => !failedProbabilityChecks.has(x));
4016 const successfulNewEntriesForRecursion = successfulNewEntries.filter(x => !x.preventRecursion);4023 const successfulNewEntriesForRecursion = successfulNewEntries.filter(x => !x.preventRecursion);
40174024
4025 console.debug(`[WI] --- LOOP #${count} RESULT ---`);
4018 if (!newEntries.length) {4026 if (!newEntries.length) {
4019 console.debug('[WI] No new entries activated, stopping');4027 console.debug('[WI] No new entries activated.');
4020 } else if (!successfulNewEntries.length) {4028 } else if (!successfulNewEntries.length) {
4021 console.debug('[WI] Probability checks failed for all activated entries, stopping');4029 console.debug('[WI] Probability checks failed for all activated entries. No new entries activated.');
4022 } else {4030 } else {
4023 console.debug(`[WI] Successfully activated ${successfulNewEntries.length} new entries to prompt. ${allActivatedEntries.size} total entries activated.`, successfulNewEntries);4031 console.debug(`[WI] Successfully activated ${successfulNewEntries.length} new entries to prompt. ${allActivatedEntries.size} total entries activated.`, successfulNewEntries);
4024 }4032 }
40254033
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 // After processing and rolling entries is done, see if we should continue with normal recursion4039 // After processing and rolling entries is done, see if we should continue with normal recursion
4027 if (world_info_recursive && !token_budget_overflowed && successfulNewEntriesForRecursion.length) {4040 if (world_info_recursive && !token_budget_overflowed && successfulNewEntriesForRecursion.length) {
4028 nextScanState = scan_state.RECURSION;4041 nextScanState = scan_state.RECURSION;
4042 logNextState('[WI] Found', successfulNewEntriesForRecursion.length, 'new entries for recursion');
4029 }4043 }
40304044
4031 // If we are inside min activations scan, and we have recursive buffer, we should do a recursive scan before increasing the buffer again4045 // If we are inside min activations scan, and we have recursive buffer, we should do a recursive scan before increasing the buffer again
4032 // There might be recurse-trigger-able entries that match the buffer, so we need to check that4046 // There might be recurse-trigger-able entries that match the buffer, so we need to check that
4033 if (world_info_recursive && !token_budget_overflowed && scanState === scan_state.MIN_ACTIVATIONS && buffer.hasRecurse()) {4047 if (world_info_recursive && !token_budget_overflowed && scanState === scan_state.MIN_ACTIVATIONS && buffer.hasRecurse()) {
4034 nextScanState = scan_state.RECURSION;4048 nextScanState = scan_state.RECURSION;
4049 logNextState('[WI] Min Activations run done, whill will always be followed by a recursive scan');
4035 }4050 }
40364051
4037 // If scanning is planned to stop, but min activations is set and not satisfied, check if we should continue4052 // 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 ) || (buffer.getDepth() > chat.length);4060 ) || (buffer.getDepth() > chat.length);
40464061
4047 if (!over_max) {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 nextScanState = scan_state.MIN_ACTIVATIONS; // loop4063 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 buffer.advanceScan();4065 buffer.advanceScan();
4051 } else {4066 } else {
4052 console.debug(`[WI] Min activations not reached (${allActivatedEntries.size}/${world_info_min_activations}), but reached on of depth. Stopping`);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 if (nextScanState === scan_state.NONE && availableRecursionDelayLevels.length) {4072 if (nextScanState === scan_state.NONE && availableRecursionDelayLevels.length) {
4058 nextScanState = scan_state.RECURSION;4073 nextScanState = scan_state.RECURSION;
4059 currentRecursionDelayLevel = availableRecursionDelayLevels.shift();4074 currentRecursionDelayLevel = availableRecursionDelayLevels.shift();
4075 logNextState('[WI] Open delayed recursion levels left. Preparing next delayed recursion level', currentRecursionDelayLevel, '. Still delayed:', availableRecursionDelayLevels);
4060 }4076 }
40614077
4062 // Final check if we should really continue scan, and extend the current WI recurse buffer4078 // 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 .map(x => x.content).join('\n');4082 .map(x => x.content).join('\n');
4067 buffer.addRecurse(text);4083 buffer.addRecurse(text);
4068 allActivatedText = (text + '\n' + allActivatedText);4084 allActivatedText = (text + '\n' + allActivatedText);
4085 } else {
4086 logNextState('[WI] Scan done. No new entries to prompt. Stopping.');
4069 }4087 }
4070 }4088 }
40714089