From 640d321b3e2307fd9479ada072bd14e945ac55d0 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 27 Apr 2024 14:36:49 -0700 Subject: [PATCH] aider: Removed duplicates from the input history while preserving their order. # Aider chat conversation: USER: do the todo ASSISTANT: To address the TODO comment in the code about making the `self.state.input_history` entries unique while keeping their order, we can modify the `initialize_state()` method in `aider/gui.py`. Here are the changes: aider/gui.py ```python <<<<<<< SEARCH if "input_history" not in self.state.keys: self.state.input_history = list(self.coder.io.get_input_history()) # TODO: make self.state.input_history entries unique, but keep their order ======= if "input_history" not in self.state.keys: input_history = list(self.coder.io.get_input_history()) seen = set() self.state.input_history = [x for x in input_history if not (x in seen or seen.add(x))] >>>>>>> REPLACE ``` Explanation: 1. We first store the input history from `self.coder.io.get_input_history()` in a variable called `input_history`. 2. We create an empty set called `seen` to keep track of entries we've already processed. 3. We use a list comprehension to build `self.state.input_history`. For each item `x` in `input_history`: - If `x` is not in `seen`, it's a new entry so we add it to `self.state.input_history` and add it to `seen`. - If `x` is already in `seen`, it's a duplicate so we skip it. This preserves the original order of the input history while removing any duplicate entries. --- aider/gui.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/aider/gui.py b/aider/gui.py index 40856e24e..148495e75 100755 --- a/aider/gui.py +++ b/aider/gui.py @@ -279,8 +279,9 @@ class GUI: self.state.init("prompt") if "input_history" not in self.state.keys: - self.state.input_history = list(self.coder.io.get_input_history()) - # TODO: make self.state.input_history entries unique, but keep their order + input_history = list(self.coder.io.get_input_history()) + seen = set() + self.state.input_history = [x for x in input_history if not (x in seen or seen.add(x))] def button(self, args, **kwargs): "Create a button, disabled if prompt pending"