From e63d8cecbb6f1a33e9653c8f2bb966d153cd806a Mon Sep 17 00:00:00 2001 From: kwaroran Date: Fri, 26 May 2023 03:45:06 +0900 Subject: [PATCH] [feat] impoved supamemory --- src/ts/process/supaMemory.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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) + } }