[feat] impoved supamemory

This commit is contained in:
kwaroran
2023-05-26 03:45:06 +09:00
parent cec5074dce
commit e63d8cecbb

View File

@@ -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)
}
}