Commit graph

23 commits

Author SHA1 Message Date
Paul Gauthier
43b79b0c2d refac 2023-05-24 21:39:36 -07:00
Paul Gauthier
7e6ea0660d Refactor show_messages function to accept an optional title parameter and remove unused code. 2023-05-19 10:57:24 -07:00
Paul Gauthier
07da14d3c7 make line numbers optional 2023-05-18 10:04:13 -07:00
Paul Gauthier
891d5b2263 aider: Added line numbers to the output of the get_quoted_file function.
# Context:
USER: git get_files_content prefix each line with a line number, starting at 1, padded out like '  1'
ASSISTANT: To add line numbers to the `get_files_content` method, we will modify the method in the `aider/coder.py` file. We will read the file content line by line and add the line number with padding to each line.

Here's the change:

```python
aider/coder.py
<<<<<<< ORIGINAL
    def get_files_content(self, fnames=None):
        if not fnames:
            fnames = self.abs_fnames

        prompt = ""
        for fname in fnames:
            relative_fname = self.get_rel_fname(fname)
            prompt += utils.quoted_file(fname, relative_fname)
        return prompt
=======
    def get_files_content(self, fnames=None):

^C KeyboardInterrupt
USER: sorry, in get_quoted_file prefix each line with a line number, starting at 1, padded out like '  1'
ASSISTANT:
^C KeyboardInterrupt
USER: Please note that I shared content of these additional files: aider/utils.py
ASSISTANT: To add line
^C KeyboardInterrupt
USER: in get_quoted_file prefix each line with a line number, starting at 1, padded out like '  1'
ASSISTANT: To add line numbers to the `get_quoted_file` function in the `aider/utils.py` file, we will read the file content line by line and add the line number with padding to each line.

Here's the change:

```python
aider/utils.py
<<<<<<< ORIGINAL
def quoted_file(fname, display_fname):
    prompt = "\n"
    prompt += display_fname
    prompt += "\n```\n"
    prompt += Path(fname).read_text()
    prompt += "\n```\n"
    return prompt
=======
def quoted_file(fname, display_fname):
    prompt = "\n"
    prompt += display_fname
    prompt += "\n```\n"
    file_content = Path(fname).read_text()
    lines = file_content.splitlines()
    for i, line in enumerate(lines, start=1):
        prompt += f"{i:3d} {line}\n"
    prompt += "```\n"
    return prompt
>>>>>>> UPDATED
```

This change will add line numbers to the output of the `get_quoted_file` function, starting at 1 and padded out like '  1'.
2023-05-18 07:00:50 -07:00
Paul Gauthier
9a413d351d black formatting 2023-05-17 18:24:35 -07:00
Paul Gauthier
cc0ee034f4 aider: Added a check to ensure that part appears in whole exactly once in try_dotdotdots.
# Context:
USER: in try_dotdotdots, after checking that part is in whole add a check that part is in whole exactly 1 time
ASSISTANT: ```python
aider/utils.py
<<<<<<< ORIGINAL
        if part not in whole:
            raise ValueError("No perfect matching chunk in edit block with ...")

        whole = whole.replace(part, replace)
=======
        if whole.count(part) != 1:
            raise ValueError("No perfect matching chunk in edit block with ... or part appears more than once")

        whole = whole.replace(part, replace, 1)
>>>>>>> UPDATED
```
2023-05-17 16:15:09 -07:00
Paul Gauthier
0c05e3d957 Handle case where part="" and replace is non-empty 2023-05-14 11:07:22 -07:00
Paul Gauthier
e9debe71e8 Attempt to honot edit blocks which elide content using ... 2023-05-14 11:00:45 -07:00
Paul Gauthier
ab68022fb9 wip: Added a dry-run option to do_replace function. 2023-05-14 10:15:08 -07:00
Paul Gauthier
0b8690654e aider: Added dry_run parameter to do_replace function and passed it from Coder class.
# Context:
USER: pass dry run into do_replace and only write to the file if false
ASSISTANT: To implement this change, we need to modify the `do_replace` function in the `aider/utils.py` file. We will add a new parameter `dry_run` to the function and only write to the file if `dry_run` is `False`.

Here's the change:

```python
aider/utils.py
<<<<<<< ORIGINAL
def do_replace(fname, before_text, after_text):
=======
def do_replace(fname, before_text, after_text, dry_run=False):
>>>>>>> UPDATED
    before_text = strip_quoted_wrapping(before_text, fname)
    after_text = strip_quoted_wrapping(after_text, fname)
    fname = Path(fname)

    # does it want to make a new file?
    if not fname.exists() and not before_text.strip():
        fname.touch()

    content = fname.read_text()

    if not before_text.strip():
        if content:
            new_content = content + after_text
        else:
            # first populating an empty file
            new_content = after_text
    else:
        new_content = replace_most_similar_chunk(content, before_text, after_text)
        if not new_content:
            return

    if not dry_run:
        fname.write_text(new_content)
    return True
```

Now, you need to pass the `dry_run` parameter from the `Coder` class in the `aider/coder.py` file to the `do_replace` function. Here's the change:

```python
aider/coder.py
<<<<<<< ORIGINAL
if utils.do_replace(full_path, original, updated):
=======
if utils.do_replace(full_path, original, updated, self.dry_run):
>>>>>>> UPDATED
    self.io.tool(f"Applied edit to {path}")
else:
    self.io.tool_error(f"Failed to apply edit to {path}")
```

These changes will ensure that the file is only written to when `dry_run` is `False`.
2023-05-14 10:14:20 -07:00
Paul Gauthier
92e091f5a6 fix bug if ORIG/UPD block is missing trailing newline; added test 2023-05-12 13:30:39 -07:00
Paul Gauthier
d45b7ae752 handle filenames above the triple quotes 2023-05-11 22:59:02 -07:00
Paul Gauthier
6e4f17d377 cleanup 2023-05-11 22:06:32 -07:00
Paul Gauthier
684b0e4964 Provide structured errors to GPT if it generates malformed ORIG/UPD blocks 2023-05-11 22:06:02 -07:00
Paul Gauthier
ae41782cb4 wip 2023-05-11 21:05:15 -07:00
Paul Gauthier
797372c69e refactor orig/upd into utils 2023-05-11 20:57:27 -07:00
Paul Gauthier
6133eb61c1 fix tests and bug 2023-05-11 17:15:19 -07:00
Paul Gauthier
35a4a14a6a Avoid sending 2 copies of the added files 2023-05-10 19:13:33 -07:00
Paul Gauthier
b139dbf475 refactor 2023-05-10 18:41:36 -07:00
Paul Gauthier
79d38b5d68 handle the simple replace case quickly 2023-05-10 18:21:41 -07:00
Paul Gauthier
923e42c176 fixed off by 1 error in replace_most_similar_chunk() 2023-05-10 16:22:08 -07:00
Paul Gauthier
2339dd4803 aider: Added display_fname arg to quoted_file and updated call to quoted_file to pass relative file path.
# Context:
USER: add a display_fname arg to quoted_file. add it, not fname, into the prompt. change the call to quoted_file to pass along the fname relative to self.root
ASSISTANT: To add a `display_fname` argument to the `quoted_file` function and update the call to `quoted_file`, follow these changes:

1. Add the `display_fname` argument to the `quoted_file` function definition.
2. Replace `fname` with `display_fname` in the prompt string.
3. Update the call to `quoted_file` in the `get_files_content` method to pass the relative file path.

Here are the code changes:

```python
aider/utils.py
<<<<<<< ORIGINAL
def quoted_file(fname):
    prompt = "\n"
    prompt += fname
=======
def quoted_file(fname, display_fname):
    prompt = "\n"
    prompt += display_fname
>>>>>>> UPDATED
    prompt += "\n```\n"
    prompt += Path(fname).read_text()
    prompt += "\n```\n"
    return prompt
```

```python
aider/coder.py
<<<<<<< ORIGINAL
        for fname in self.fnames:
            prompt += utils.quoted_file(fname)
=======
        for fname in self.fnames:
            relative_fname = os.path.relpath(fname, self.root)
            prompt += utils.quoted_file(fname, relative_fname)
>>>>>>> UPDATED
        return prompt
```
2023-05-10 09:24:27 -07:00
Paul Gauthier
984e2f78ce moved into subdir 2023-05-09 10:52:18 -07:00
Renamed from utils.py (Browse further)