From 0317a941f1a60d0b9a368007d342751be8fb28b6 Mon Sep 17 00:00:00 2001 From: Bo26fhmC5M <88071760+Bo26fhmC5M@users.noreply.github.com> Date: Thu, 2 Jan 2025 20:52:37 +0900 Subject: [PATCH] fix: token calculation for HypaV2 --- src/ts/process/memory/hypav2.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ts/process/memory/hypav2.ts b/src/ts/process/memory/hypav2.ts index 917387bd..0edcd118 100644 --- a/src/ts/process/memory/hypav2.ts +++ b/src/ts/process/memory/hypav2.ts @@ -381,6 +381,12 @@ export async function hypaMemoryV2( const lastChatIndex = chats.findIndex(chat => chat.memo === lastChatMemo); if (lastChatIndex !== -1) { idx = lastChatIndex + 1; + + // Subtract tokens of removed chats + const removedChats = chats.slice(0, lastChatIndex + 1); + for (const chat of removedChats) { + currentTokens -= await tokenizer.tokenizeChat(chat); + } } } // Starting chat index of new mainChunk to be generated