From c17e4546081db91143f8e88a18645561c013252f Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 5 Jun 2023 11:31:47 -0700 Subject: [PATCH] Added /clear cmd --- aider/coder.py | 3 ++- aider/commands.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/aider/coder.py b/aider/coder.py index 93a86827d..97fe0fcf5 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -72,7 +72,6 @@ class Coder: else: self.console = Console(force_terminal=True, no_color=True) - self.commands = Commands(self.io, self) if not self.check_model_availability(main_model): main_model = Models.GPT35.value @@ -89,6 +88,8 @@ class Coder: self.show_diffs = show_diffs + self.commands = Commands(self.io, self) + self.set_repo(fnames) if self.repo: diff --git a/aider/commands.py b/aider/commands.py index 05acfb7a6..8a3e08519 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -4,6 +4,7 @@ import subprocess import sys import git +import tiktoken from prompt_toolkit.completion import Completion from aider import prompts @@ -14,6 +15,7 @@ class Commands: def __init__(self, io, coder): self.io = io self.coder = coder + self.tokenizer = tiktoken.encoding_for_model(coder.main_model) def is_command(self, inp): if inp[0] == "/": @@ -76,6 +78,13 @@ class Commands: commit_message = args.strip() self.coder.commit(message=commit_message, which="repo_files") + def cmd_clear(self, args): + "Clear the chat history and drop all files from the chat context" + + self.coder.abs_fnames = set() + self.coder.done_messages = [] + self.coder.cur_messages = [] + def cmd_undo(self, args): "Undo the last git commit if it was done by aider" if not self.coder.repo: