From c26917851fa460d0947d3ccd3ec37241f3c02bcd Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 22 Jul 2023 10:34:48 -0300 Subject: [PATCH] Added a `ChatSummary` object to `Coder` class and used it to summarize chat history. --- aider/coders/base_coder.py | 5 ++++- aider/history.py | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index bca01469b..f0d7ab66f 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -20,6 +20,7 @@ from aider.commands import Commands from aider.repo import GitRepo from aider.repomap import RepoMap from aider.sendchat import send_with_retries +from aider.history import ChatSummary from ..dump import dump # noqa: F401 @@ -199,6 +200,8 @@ class Coder: if self.repo: self.repo.add_new_files(fnames) + self.summarizer = ChatSummary() + # validate the functions jsonschema if self.functions: for function in self.functions: @@ -353,7 +356,7 @@ class Coder: def move_back_cur_messages(self, message): self.done_messages += self.cur_messages - #self.done_messages = summarize_chat_history(self.done_messages) + self.done_messages = self.summarizer.summarize(self.done_messages) if message: self.done_messages += [ diff --git a/aider/history.py b/aider/history.py index 214198f96..6c164a076 100644 --- a/aider/history.py +++ b/aider/history.py @@ -9,7 +9,7 @@ from aider.sendchat import simple_send_with_retries class ChatSummary: - def __init__(self, model, max_tokens=1024): + def __init__(self, model=models.GPT35.name, max_tokens=1024): self.tokenizer = tiktoken.encoding_for_model(model) self.max_tokens = max_tokens @@ -38,7 +38,6 @@ class ChatSummary: head = messages[:num] tail = messages[num:] - print("=" * 20) summary = self.summarize_all(head) tail_tokens = sum(tokens for tokens, msg in sized[num:])