From 83b79fa48dfe305b28395e11c060ee21d3b58e64 Mon Sep 17 00:00:00 2001 From: LightningHyperBlaze45654 <73149145+LightningHyperBlaze45654@users.noreply.github.com> Date: Sun, 1 Dec 2024 17:40:21 -0800 Subject: [PATCH] fix: chunks not being filtered correctly need to check if chat.memo is actually a unique uuid4/uuid5 or else it will be broken --- src/ts/process/memory/hypav2.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/ts/process/memory/hypav2.ts b/src/ts/process/memory/hypav2.ts index ee6a151b..b437681c 100644 --- a/src/ts/process/memory/hypav2.ts +++ b/src/ts/process/memory/hypav2.ts @@ -156,27 +156,33 @@ function cleanInvalidChunks( } else { // Build a set of current chat memo IDs const currentChatIds = new Set(chats.map((chat) => chat.memo)); + console.log("OpenAI Chat IDs? ", currentChatIds) - // Filter mainChunks + // 존재하지 않는 챗의 요약본 삭제 data.mainChunks = data.mainChunks.filter((chunk) => { - // Check if all chat memos in the range exist const [startIdx, endIdx] = chunk.chatRange; + // Check if all chats in the range exist for (let i = startIdx; i <= endIdx; i++) { if (!currentChatIds.has(chats[i]?.memo)) { - return false; // Chat no longer exists, remove this mainChunk + return false; // false로 filtering } } return true; }); - // Similarly for chunks - data.chunks = data.chunks.filter(() => { - // Since chunks are associated with mainChunks, they have been filtered already + // 같은거, 근데 이건 쪼개진 chunk들에 대하여 수행 + data.chunks = data.chunks.filter((chunk) => { + const [startIdx, endIdx] = chunk.chatRange; + // 생성된 chunks는 더이상 mainChunks와 연결되지 않음. 따라서 같은 작업을 진행해야 한다. + for (let i = startIdx; i <= endIdx; i++) { + if (!currentChatIds.has(chats[i]?.memo)) { + return false; + } + } return true; }); } } - export async function hypaMemoryV2( chats: OpenAIChat[], currentTokens: number,