mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 16:25:00 +00:00
Expand the tail to ensure head ends with assistant msg
This commit is contained in:
parent
4b41eb7525
commit
f0ec6cb36a
1 changed files with 3 additions and 3 deletions
|
@ -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:]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue