From aa8ead2f2e6b25ae547a6a36afd774b4628b573b Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 18 May 2023 17:30:34 -0700 Subject: [PATCH] aider: Made the two history files optional. # Context: USER: make the two history files optional ASSISTANT: To make the two history files optional, we will modify the `__init__` method of the `InputOutput` class in the `aider/io.py` file. We will set the default values of `input_history_file` and `chat_history_file` to `None`. Then, we will add conditions to check if these variables are not `None` before using them. ```python aider/io.py <<<<<<< ORIGINAL def __init__(self, pretty, yes, input_history_file, chat_history_file, input=None, output=None): ======= def __init__(self, pretty, yes, input_history_file=None, chat_history_file=None, input=None, output=None): >>>>>>> UPDATED ``` ```python aider/io.py <<<<<<< ORIGINAL session = PromptSession( message=show, completer=completer_instance, history=FileHistory(self.input_history_file), style=style, reserve_space_for_menu=4, complete_style=CompleteStyle.MULTI_COLUMN, input=self.input, output=self.output, ) ======= session_kwargs = { "message": show, "completer": completer_instance, "style": style, "reserve_space_for_menu": 4, "complete_style": CompleteStyle.MULTI_COLUMN, "input": self.input, "output": self.output, } if self.input_history_file is not None: session_kwargs["history"] = FileHistory(self.input_history_file) session = PromptSession(**session_kwargs) >>>>>>> UPDATED ``` ```python aider/io.py <<<<<<< ORIGINAL self.chat_history_file = Path(chat_history_file) ======= if chat_history_file is not None: self.chat_history_file = Path(chat_history_file) else: self.chat_history_file = None >>>>>>> UPDATED ``` ```python aider/io.py <<<<<<< ORIGINAL with self.chat_history_file.open("a") as f: f.write(text) ======= if self.chat_history_file is not None: with self.chat_history_file.open("a") as f: f.write(text) >>>>>>> UPDATED ``` These changes will make the history files optional. --- aider/io.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/aider/io.py b/aider/io.py index 10c5b6bbc..8dd0719c8 100644 --- a/aider/io.py +++ b/aider/io.py @@ -51,13 +51,16 @@ class FileContentCompleter(Completer): class InputOutput: - def __init__(self, pretty, yes, input_history_file, chat_history_file, input=None, output=None): + def __init__(self, pretty, yes, input_history_file=None, chat_history_file=None, input=None, output=None): self.input = input self.output = output self.pretty = pretty self.yes = yes self.input_history_file = input_history_file - self.chat_history_file = Path(chat_history_file) + if chat_history_file is not None: + self.chat_history_file = Path(chat_history_file) + else: + self.chat_history_file = None if pretty: self.console = Console() @@ -99,16 +102,18 @@ class InputOutput: if multiline_input: show = ". " - session = PromptSession( - message=show, - completer=completer_instance, - history=FileHistory(self.input_history_file), - style=style, - reserve_space_for_menu=4, - complete_style=CompleteStyle.MULTI_COLUMN, - input=self.input, - output=self.output, - ) + session_kwargs = { + "message": show, + "completer": completer_instance, + "style": style, + "reserve_space_for_menu": 4, + "complete_style": CompleteStyle.MULTI_COLUMN, + "input": self.input, + "output": self.output, + } + if self.input_history_file is not None: + session_kwargs["history"] = FileHistory(self.input_history_file) + session = PromptSession(**session_kwargs) line = session.prompt() if line.strip() == "{" and not multiline_input: multiline_input = True @@ -194,5 +199,6 @@ class InputOutput: text = text + " \n" if not text.endswith("\n"): text += "\n" - with self.chat_history_file.open("a") as f: - f.write(text) + if self.chat_history_file is not None: + with self.chat_history_file.open("a") as f: + f.write(text)