aider icon indicating copy to clipboard operation
aider copied to clipboard

Make the LLM understand when some but not all edits are applied due to a diff error

Open cranyy opened this issue 1 year ago • 2 comments

When asking questions or reporting issues, it is very helpful if you can include:

Aider v0.22.1-dev
Add .aider* to .gitignore (recommended)? n
Model: gpt-4-1106-preview using udiff edit format
Git repo: .git with 140 files
Repo-map: using 1024 tokens

Maybe I am missing a command or I am doing something wrong, but everytime When you get the error "Malformed response ... hunk failed to apply" and multiple things have been changed but 1 has gone awry, aider actually applies the edits across the board, except for the place the hunk failed part. then it tries again and again and it keeps appending edits to the non-malformed pieces over and over again until you get something like this :

def file_management_task(self, agent, company):
    """
    Task for the File Agent to demonstrate file management operations using specific commands.
    """
    current_date = datetime.now().strftime("%Y%m%d")
    return Task(description=dedent(f"""
        As a File Agent, your task is to demonstrate file management operations. You will:

        
        Use the `copy_file` command to copy the file 'table.docx' to a new file named '{company}_table_{current_date}.docx'.
       Then state the newly created files name. 

        
        Use the `copy_file` command to copy the file 'table.docx' to a new file named '{company}_table_{current_date}.docx'.
        Then add the file name to the shared_dict with the key 'file_name'.
        State the newly created file's name.

        # Use the `copy_file` command to copy the file 'table.docx' to a new file named '{company}_table_{current_date}.docx'.
        # Then add the file name to the shared_dict with the key 'file_name'.
        # State the newly created file's name.
        # Use the `copy_file` command to copy the file 'table.docx' to a new file named '{company}_table_{current_date}.docx'.
        # Then add the file name to the shared_dict with the key 'file_name'.
        # State the newly created file's name.
        """),
        agent=agent

And then if you want to revert it (even though it didnt commit) :

> /undo

The repository has uncommitted changes in files that were modified in the last commit. Please commit or stash them
before undoing.

Expected behavior: Maybe if there is an incorrect hunk, no edits should be applied at all anywhere to avoid this issue. Possible Solution: Adding a /revert command or something along these lines that will undo the last EDIT made by aider and not commit

Thank you for this project, much love for it and the effort you put into it

cranyy avatar Jan 30 '24 15:01 cranyy

Within the Aider interface you can simply enter /help at any time to print out a full list of available commands. One of them is exactly what you're looking for:

/undo Undo the last git commit if it was done by aider

You should also familiarize yourself with the command options listed by entering aider --help in your terminal (not in the Aider interface). One of the options available there may also be useful to you:

  --auto-commits, --no-auto-commits
                        Enable/disable auto commit of GPT changes (default:
                        True) [env var: AIDER_AUTO_COMMITS]

You can use this command one of three ways:

  1. When launching aider by adding the flag like so: aider --no-auto-commits. This behavior will then apply for the duration of your session, and you can simply use that every time you launch Aider.

  2. If you want the behavior to persist every time you run Aider without using the option after the command, you can also add it to an .aider.conf.yml file like so:

auto-commits: false
  1. Lastly, as an alternative to the yaml method, you can define it as an environment variable in your shell profile like so:
export AIDER_AUTO_COMMITS="false"

Hope this helps, and as with any software, you really ought to read the docs. Aider is like any other tool in that you will get far more out of it by simply familiarizing yourself with how it works.

diverged avatar Feb 05 '24 03:02 diverged

Thanks for filing this issue. This is an area where I want to make some improvements.

There is value in aider applying as many of the edits as possible. This way only the failing edits need to be sent back to GPT as errors and GPT only has to re-send those failed edits. But currently GPT-4 turbo isn't always understanding that the successful edits were applied -- even though it is being shown the updated copies of the files and being told that explicitly.

So there's room for improvement both in how aider works with GPT and how aider works with the user's local git state.

paul-gauthier avatar Feb 07 '24 18:02 paul-gauthier

Aider now prompts correctly about partially applied edit sets. I'm going to close this issue for now, but feel free to add a comment here and I will re-open or file a new issue any time.

paul-gauthier avatar Jun 20 '24 14:06 paul-gauthier