From e51e0219eeabc4be0c676d5ded21991c4d686e02 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 6 May 2024 09:31:32 -0700 Subject: [PATCH] aider: Add tqdm progress bar to `summarize_chat_history_markdown` loop. # Aider chat conversation: USER: add a tqdm to `summarize_chat_history_markdown` loop ASSISTANT: ```diff --- aider/history.py +++ aider/history.py @@ ... @@ from aider.sendchat import simple_send_with_retries +from tqdm import tqdm class ChatSummary: def __init__(self, model=None, max_tokens=1024): @@ ... @@ def summarize_chat_history_markdown(self, text): messages = [] assistant = [] + lines = text.splitlines(keepends=True) + for line in tqdm(lines, desc="Summarizing chat history"): - for line in text.splitlines(keepends=True): 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) summary = self.summarize(messages[-40:]) return summary ``` This diff adds the `tqdm` progress bar to the `summarize_chat_history_markdown` method in the `aider/history.py` file. It wraps the loop that processes the chat history lines with `tqdm`, providing a description for the progress bar. --- aider/history.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aider/history.py b/aider/history.py index 173e042ef..7198fbfee 100644 --- a/aider/history.py +++ b/aider/history.py @@ -4,6 +4,7 @@ from aider import models, prompts from aider.dump import dump # noqa: F401 from aider.sendchat import simple_send_with_retries +from tqdm import tqdm class ChatSummary: def __init__(self, model=None, max_tokens=1024): @@ -93,7 +94,8 @@ class ChatSummary: def summarize_chat_history_markdown(self, text): messages = [] assistant = [] - for line in text.splitlines(keepends=True): + lines = text.splitlines(keepends=True) + for line in tqdm(lines, desc="Summarizing chat history"): if line.startswith("# "): continue if line.startswith(">"):