Expand the tail to ensure head ends with assistant msg

This commit is contained in:
Paul Gauthier 2023-07-25 06:58:41 -03:00
parent 4b41eb7525
commit f0ec6cb36a

View file

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