[feat] added memory limit line
This commit is contained in:
@@ -238,18 +238,21 @@ export async function sendChat(chatProcessIndex = -1):Promise<boolean> {
|
||||
chats = sp.chats
|
||||
currentTokens = sp.currentTokens
|
||||
currentChat.supaMemoryData = sp.memory ?? currentChat.supaMemoryData
|
||||
currentChat.lastMemory = sp.lastId ?? currentChat.lastMemory
|
||||
}
|
||||
else{
|
||||
while(currentTokens > maxContextTokens){
|
||||
if(chats.length <= 1){
|
||||
alertError(language.errors.toomuchtoken)
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
currentTokens -= (await tokenize(chats[0].content) + 1)
|
||||
chats.splice(0, 1)
|
||||
}
|
||||
}
|
||||
currentChat.lastMemory = chats[0].memo
|
||||
console.log(currentChat.lastMemory)
|
||||
}
|
||||
let bias:{[key:number]:number} = {}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { tokenize } from "../tokenizer";
|
||||
import { findCharacterbyId } from "../util";
|
||||
import { requestChatData } from "./request";
|
||||
|
||||
export async function supaMemory(chats:OpenAIChat[],currentTokens:number,maxContextTokens:number,room:Chat,char:character|groupChat): Promise<{ currentTokens: number; chats: OpenAIChat[]; error?:string; memory?:string}>{
|
||||
export async function supaMemory(chats:OpenAIChat[],currentTokens:number,maxContextTokens:number,room:Chat,char:character|groupChat): Promise<{ currentTokens: number; chats: OpenAIChat[]; error?:string; memory?:string;lastId?:string}>{
|
||||
const db = get(DataBase)
|
||||
console.log("Memory: " + currentTokens)
|
||||
|
||||
@@ -147,7 +147,8 @@ export async function supaMemory(chats:OpenAIChat[],currentTokens:number,maxCont
|
||||
return {
|
||||
currentTokens: currentTokens,
|
||||
chats: chats,
|
||||
memory: lastId + '\n' + supaMemory
|
||||
memory: lastId + '\n' + supaMemory,
|
||||
lastId: lastId
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user