diff --git a/src/ts/process/supaMemory.ts b/src/ts/process/supaMemory.ts index 5810de36..73f0ab6d 100644 --- a/src/ts/process/supaMemory.ts +++ b/src/ts/process/supaMemory.ts @@ -173,6 +173,9 @@ export async function supaMemory(chats:OpenAIChat[],currentTokens:number,maxCont } const tokens = await tokenize(cont.content) + 1 if((chunkSize + tokens) > maxChunkSize){ + if(stringlizedChat === ''){ + stringlizedChat += `${cont.role === 'assistant' ? char.type === 'group' ? '' : char.name : db.username}: ${cont.content}\n\n` + } lastId = cont.memo break } @@ -193,6 +196,25 @@ export async function supaMemory(chats:OpenAIChat[],currentTokens:number,maxCont const tokenz = await tokenize(result + '\n\n') + 5 currentTokens += tokenz supaMemory += result.replace(/\n+/g,'\n') + '\n\n' + + let SupaMemoryList = supaMemory.split('\n\n') + if(SupaMemoryList.length >= 5){ + const oldSupaMemory = supaMemory + let modifies = [] + for(let i=0;i<3;i++){ + modifies.push(SupaMemoryList.shift()) + } + const result = await summarize(supaMemory) + if(typeof(result) !== 'string'){ + return result + } + + modifies.unshift(result.replace(/\n+/g,'\n')) + supaMemory = modifies.join('\n\n') + '\n\n' + + currentTokens -= await tokenize(oldSupaMemory) + currentTokens += await tokenize(supaMemory) + } }