fix: token calculation for HypaV2

This commit is contained in:
Bo26fhmC5M
2025-01-02 20:52:37 +09:00
parent 2b92582df4
commit 0317a941f1

View File

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