From 602a0c7c315144b838a2a06e6a3338f91f5ddb83 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 11 May 2024 07:52:06 -0700 Subject: [PATCH] refac utils.split_chat_history_markdown --- aider/coders/base_coder.py | 2 +- aider/history.py | 28 ---------------------------- aider/utils.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index d336b63a2..a97eaa3fb 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -299,7 +299,7 @@ class Coder: if not self.done_messages: history_md = self.io.read_text(self.io.chat_history_file) if history_md: - self.done_messages = self.summarizer.split_chat_history_markdown(history_md) + self.done_messages = utils.split_chat_history_markdown(history_md) self.summarize_start() # validate the functions jsonschema diff --git a/aider/history.py b/aider/history.py index a93e3141c..e80b80e1c 100644 --- a/aider/history.py +++ b/aider/history.py @@ -104,34 +104,6 @@ class ChatSummary: return [dict(role="user", content=summary)] - def split_chat_history_markdown(self, text): - messages = [] - assistant = [] - lines = text.splitlines(keepends=True) - for line in lines: - if line.startswith("# "): - continue - if line.startswith(">"): - continue - if line.startswith("#### /"): - continue - - if line.startswith("#### "): - if assistant: - assistant = "".join(assistant) - if assistant.strip(): - messages.append(dict(role="assistant", content=assistant)) - assistant = [] - - content = line[5:] - if content.strip() and content.strip() != "": - messages.append(dict(role="user", content=line[5:])) - continue - - assistant.append(line) - - return messages - def main(): parser = argparse.ArgumentParser() diff --git a/aider/utils.py b/aider/utils.py index 81c20c81b..f5d58090f 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -105,3 +105,32 @@ def show_messages(messages, title=None, functions=None): if functions: dump(functions) + + +def split_chat_history_markdown(text): + messages = [] + assistant = [] + lines = text.splitlines(keepends=True) + for line in lines: + if line.startswith("# "): + continue + if line.startswith(">"): + continue + if line.startswith("#### /"): + continue + + if line.startswith("#### "): + if assistant: + assistant = "".join(assistant) + if assistant.strip(): + messages.append(dict(role="assistant", content=assistant)) + assistant = [] + + content = line[5:] + if content.strip() and content.strip() != "": + messages.append(dict(role="user", content=line[5:])) + continue + + assistant.append(line) + + return messages