fixed summary creation
This commit is contained in:
@@ -59,11 +59,8 @@ async function generateSummary(episodes, existingSummary = null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function maybeSummarize(session, allEpisodes) {
|
async function maybeSummarize(session, allEpisodes) {
|
||||||
console.log('[summarization] MEMORY_URL:', MEMORY_URL)
|
|
||||||
console.log('[summarization] EXTRACTION_URL:', EXTRACTION_URL);
|
|
||||||
// 1. Sum total tokens for this session
|
// 1. Sum total tokens for this session
|
||||||
const totalTokens = allEpisodes.reduce((sum, ep) => sum + (ep.token_count || 0), 0);
|
const totalTokens = allEpisodes.reduce((sum, ep) => sum + (ep.token_count || 0), 0);
|
||||||
console.log('[summarization] totalTokens:', totalTokens, 'threshold:', THRESHOLD_TOKENS);
|
|
||||||
if (totalTokens < THRESHOLD_TOKENS) return; // under threshold — nothing to do
|
if (totalTokens < THRESHOLD_TOKENS) return; // under threshold — nothing to do
|
||||||
console.log('[summarization] fetching existing summaries...');
|
console.log('[summarization] fetching existing summaries...');
|
||||||
// 2. Fetch existing summaries for session
|
// 2. Fetch existing summaries for session
|
||||||
@@ -73,11 +70,11 @@ async function maybeSummarize(session, allEpisodes) {
|
|||||||
const summaries = await summariesRes.json();
|
const summaries = await summariesRes.json();
|
||||||
|
|
||||||
const latest = summaries.at(-1) ?? null;
|
const latest = summaries.at(-1) ?? null;
|
||||||
|
const lastCoveredId = latest
|
||||||
|
? parseInt(latest.episode_range?.split('-').at(-1)) || 0
|
||||||
|
: 0;
|
||||||
// 3. Guard — don't re-summarize until MIN_EPISODES_SINCE new episodes have accumulated
|
// 3. Guard — don't re-summarize until MIN_EPISODES_SINCE new episodes have accumulated
|
||||||
if (latest) {
|
if (latest) {
|
||||||
const lastEpisodeRange = latest.episode_range ?? '0';
|
|
||||||
const lastCoveredId = parseInt(lastEpisodeRange.split('-').at(-1)) || 0;
|
|
||||||
const newEpisodes = allEpisodes.filter(ep => ep.id > lastCoveredId);
|
const newEpisodes = allEpisodes.filter(ep => ep.id > lastCoveredId);
|
||||||
if (newEpisodes.length < MIN_EPISODES_SINCE) return;
|
if (newEpisodes.length < MIN_EPISODES_SINCE) return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user