feat: Implement HypaV3 ratio-based memory

This commit is contained in:
Bo26fhmC5M
2025-01-12 01:45:49 +09:00
parent 3b533e911f
commit 50361d7aa2
9 changed files with 1004 additions and 7 deletions

View File

@@ -29,6 +29,7 @@ import { hypaMemoryV2 } from "./memory/hypav2";
import { runLuaEditTrigger } from "./lua";
import { parseChatML } from "../parser.svelte";
import { getModelInfo, LLMFlags } from "../model/modellist";
import { hypaMemoryV3 } from "./memory/hypav3";
export interface OpenAIChat{
role: 'system'|'user'|'assistant'|'function'
@@ -790,7 +791,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
currentTokens += await tokenizer.tokenizeChat(chat)
}
if(nowChatroom.supaMemory && (DBState.db.supaModelType !== 'none' || DBState.db.hanuraiEnable || DBState.db.hypav2)){
if(nowChatroom.supaMemory && (DBState.db.supaModelType !== 'none' || DBState.db.hanuraiEnable || DBState.db.hypav2 || DBState.db.hypaV3)){
chatProcessStage.set(2)
if(DBState.db.hanuraiEnable){
const hn = await hanuraiMemory(chats, {
@@ -822,6 +823,27 @@ export async function sendChat(chatProcessIndex = -1,arg:{
currentChat = DBState.db.characters[selectedChar].chats[selectedChat];
console.log("[Expected to be updated] chat's HypaV2Data: ", currentChat.hypaV2Data)
}
else if(DBState.db.hypaV3){
console.log("Current chat's hypaV3 Data: ", currentChat.hypaV3Data)
const sp = await hypaMemoryV3(chats, currentTokens, maxContextTokens, currentChat, nowChatroom, tokenizer)
if(sp.error){
// Save new summary
if (sp.memory) {
currentChat.hypaV3Data = sp.memory
DBState.db.characters[selectedChar].chats[selectedChat].hypaV3Data = currentChat.hypaV3Data
}
console.log(sp)
alertError(sp.error)
return false
}
chats = sp.chats
currentTokens = sp.currentTokens
currentChat.hypaV3Data = sp.memory ?? currentChat.hypaV3Data
DBState.db.characters[selectedChar].chats[selectedChat].hypaV3Data = currentChat.hypaV3Data
currentChat = DBState.db.characters[selectedChar].chats[selectedChat];
console.log("[Expected to be updated] chat's HypaV3Data: ", currentChat.hypaV3Data)
}
else{
const sp = await supaMemory(chats, currentTokens, maxContextTokens, currentChat, nowChatroom, tokenizer, {
asHyper: DBState.db.hypaMemory