From f0ec6cb36aad98ce5344b95ead8a5a490d910f38 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 25 Jul 2023 06:58:41 -0300 Subject: [PATCH] Expand the tail to ensure head ends with assistant msg --- aider/history.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aider/history.py b/aider/history.py index 6b022d59b..425579e8e 100644 --- a/aider/history.py +++ b/aider/history.py @@ -40,7 +40,7 @@ class ChatSummary: half_max_tokens = self.max_tokens // 2 # Iterate over the messages in reverse order - for i in range(len(sized)-1, -1, -1): + for i in range(len(sized) - 1, -1, -1): tokens, _msg = sized[i] if tail_tokens + tokens < half_max_tokens: tail_tokens += tokens @@ -49,8 +49,8 @@ class ChatSummary: break # Ensure the head ends with an assistant message - while messages[split_index - 1]["role"] != "assistant" and split_index < len(messages): - split_index += 1 + while messages[split_index - 1]["role"] != "assistant" and split_index > 1: + split_index -= 1 head = messages[:split_index] tail = messages[split_index:]