aider is AI pair programming in your terminal https://aider.chat/
Find a file
Paul Gauthier 8be2f8086c aider: Add a test case to reproduce the issue of trying to add a directory using the /add command.
# Aider chat conversation:

USER: add a test case to reproduce this issue: Trying to add just a directory makes the program throw the following and exit:

> /add src/components

Traceback (most recent call last):
  File "/home/palmerd/.local/bin/aider", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/palmerd/.local/lib/python3.11/site-packages/aider/main.py", line 369, in main
    coder.run()
  File "/home/palmerd/.local/lib/python3.11/site-packages/aider/coders/base_coder.py", line 382, in run
    new_user_message = self.run_loop()
                       ^^^^^^^^^^^^^^^
  File "/home/palmerd/.local/lib/python3.11/site-packages/aider/coders/base_coder.py", line 446, in run_loop
    return self.commands.run(inp)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/palmerd/.local/lib/python3.11/site-packages/aider/commands.py", line 60, in run
    return self.do_run(matching_commands[0][1:], rest_inp)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/palmerd/.local/lib/python3.11/site-packages/aider/commands.py", line 45, in do_run
    return cmd_method(args)
           ^^^^^^^^^^^^^^^^
  File "/home/palmerd/.local/lib/python3.11/site-packages/aider/commands.py", line 264, in cmd_add
    content = self.io.read_text(abs_file_path)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/palmerd/.local/lib/python3.11/site-packages/aider/io.py", line 142, in read_text
    with open(str(filename), "r", encoding=self.encoding) as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IsADirectoryError: [Errno 21] Is a directory: '/home/palmerd/vue-frontend/src/components'

ASSISTANT: To reproduce this issue, we need to create a test case that tries to add a directory using the `/add` command. However, the code you've provided is not designed to handle test cases.

Could you please provide the test suite or the file where the test cases are written so that I can add a new test case?

USER: I added these *read-write* files: tests/test_commands.py

ASSISTANT: Great, we can add a test case in the `tests/test_commands.py` file. This test case will attempt to add a directory and check if the appropriate error is handled.

Here is the proposed change:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
    def test_cmd_add_no_match(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Call the cmd_add method with a non-existent file pattern
        commands.cmd_add("*.nonexistent")

        # Check if no files have been added to the chat session
        self.assertEqual(len(coder.abs_fnames), 0)
=======
    def test_cmd_add_no_match(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Call the cmd_add method with a non-existent file pattern
        commands.cmd_add("*.nonexistent")

        # Check if no files have been added to the chat session
        self.assertEqual(len(coder.abs_fnames), 0)

    def test_cmd_add_directory(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Create a directory
        os.mkdir("test_dir")

        # Call the cmd_add method with a directory
        with self.assertRaises(IsADirectoryError):
            commands.cmd_add("test_dir")
>>>>>>> UPDATED
```

This new test case `test_cmd_add_directory` creates a directory named `test_dir` and attempts to add it using the `cmd_add` method. We expect an `IsADirectoryError` to be raised in this scenario.
2023-07-10 13:17:55 -07:00
.github/workflows Run windows tests on push 2023-07-05 15:26:06 -07:00
_layouts Updated jekyll taglines 2023-06-08 16:36:51 -07:00
aider 10 retries 2023-07-10 07:38:17 -07:00
assets padding 2023-07-09 21:44:03 -07:00
benchmark preparing for v0.8.0 2023-07-06 14:03:06 -07:00
docs copy 2023-07-07 20:53:23 -07:00
examples copy 2023-07-09 19:13:26 -07:00
scripts run unit tests inside docker for safety 2023-06-26 20:37:55 -07:00
tests aider: Add a test case to reproduce the issue of trying to add a directory using the /add command. 2023-07-10 13:17:55 -07:00
.dockerignore docker environment for the whole benchmark 2023-06-29 14:19:00 -07:00
.flake8 debug 2023-05-08 22:55:55 -07:00
.pre-commit-config.yaml do isort first 2023-05-30 13:55:28 -07:00
_config.yml Updated jekyll taglines 2023-06-08 16:36:51 -07:00
CNAME Create CNAME 2023-05-15 12:54:06 -07:00
HISTORY.md Updated HISTORY 2023-07-08 09:01:48 -07:00
LICENSE.txt Added Apache 2.0 license 2023-05-15 08:29:00 -07:00
MANIFEST.in wip 2023-06-08 12:44:41 -07:00
pytest.ini Skip benchmark tests normally 2023-06-30 13:37:24 -07:00
README.md faq 2023-07-10 07:26:12 -07:00
requirements.txt validate all jsonschemas 2023-07-02 06:36:42 -07:00
setup.py fix; bump to 0.6.4 2023-06-17 07:08:45 -07:00

aider is GPT powered coding in your terminal

aider is a command-line chat tool that allows you to write and edit code with OpenAI's GPT models. You can ask GPT to help you start a new project, or modify code in your existing git repo. Aider makes it easy to git commit, diff & undo changes proposed by GPT without copy/pasting. It also has features that help GPT-4 understand and modify larger codebases.

aider screencast

Getting started

$ pip install aider-chat
$ export OPENAI_API_KEY=your-key-goes-here
$ aider myapp.py

Using git repo: .git
Added myapp.py to the chat.

myapp.py> change the fibonacci function from recursion to iteration

Example chat transcripts

Here are some example transcripts that show how you can chat with aider to write and edit code with GPT-4.

You can find more chat transcripts on the examples page.

Features

  • Chat with GPT about your code by launching aider from the command line with set of source files to discuss and edit together. Aider lets GPT see and edit the content of those files.
  • Request new features, changes, improvements, or bug fixes to your code. Ask for new test cases, updated documentation or code refactors.
  • Aider will apply the edits suggested by GPT directly to your source files.
  • Aider will automatically commit each changeset to your local git repo with a descriptive commit message. These frequent, automatic commits provide a safety net. It's easy to undo changes or use standard git workflows to manage longer sequences of changes.
  • You can use aider with multiple source files at once, so GPT can make coordinated code changes across all of them in a single changeset/commit.
  • Aider can give GPT-4 a map of your entire git repo, which helps it understand and modify large codebases.
  • You can also edit files by hand using your editor while chatting with aider. Aider will notice these out-of-band edits and ask if you'd like to commit them. This lets you bounce back and forth between the aider chat and your editor, to collaboratively code with GPT.

Installation

  1. Install the package with pip:
  • PyPI: python -m pip install aider-chat
  • GitHub: python -m pip install git+https://github.com/paul-gauthier/aider.git
  • Local clone: python -m pip install -e .
  1. Set up your OpenAI API key:
  • As an environment variable:
    • export OPENAI_API_KEY=sk-... on Linux or Mac
    • setx OPENAI_API_KEY sk-... in Windows PowerShell
  • Or include openai-api-key: sk-... in an .aider.conf.yml file in your home directory or at the root of your git repo, alongside the .git dir.
  1. Make sure you have git installed.

  2. Optionally, install universal ctags. This is helpful if you plan to use aider and GPT-4 with repositories that have more than a handful of files. This allows aider to build a map of your entire git repo and share it with GPT to help it better understand and modify large codebases. See the FAQ entry about ctags for more info.

Usage

Run the aider tool by executing the following command:

aider <file1> <file2> ...

If your pip install did not place the aider executable on your path, you can invoke aider like this:

python -m aider.main <file1> <file2>

Replace <file1>, <file2>, etc., with the paths to the source code files you want to work on. These files will be "added to the chat session", so that GPT can see their contents and edit them according to your instructions.

You can also just launch aider anywhere in a git repo without naming files on the command line. It will discover all the files in the repo. You can then add and remove individual files in the chat session with the /add and /drop chat commands described below. If you or GPT mention one of the repo's filenames in the conversation, aider will ask if you'd like to add it to the chat.

Aider will work best if you think about which files need to be edited to make your change and add them to the chat. Aider has some ability to help GPT figure out which files to edit all by itself, but the most effective approach is to explicitly add the needed files to the chat yourself.

Aider also has many additional command-line options, environment variables or configuration file to set many options. See aider --help for details.

In-chat commands

Aider supports commands from within the chat, which all start with /. Here are some of the most useful in-chat commands:

  • /add <file>: Add matching files to the chat session.
  • /drop <file>: Remove matching files from the chat session.
  • /undo: Undo the last git commit if it was done by aider.
  • /diff: Display the diff of the last aider commit.
  • /run <command>: Run a shell command and optionally add the output to the chat.
  • /help: Show help about all commands.

Tips

  • Think about which files need to be edited to make your change and add them to the chat. Aider has some ability to help GPT figure out which files to edit all by itself, but the most effective approach is to explicitly add the needed files to the chat yourself.
  • Large changes are best performed as a sequence of thoughtful bite sized steps, where you plan out the approach and overall design. Walk GPT through changes like you might with a junior dev. Ask for a refactor to prepare, then ask for the actual change. Spend the time to ask for code quality/structure improvements.
  • Use Control-C to safely interrupt GPT if it isn't providing a useful response. The partial response remains in the conversation, so you can refer to it when you reply to GPT with more information or direction.
  • Use the /run command to run tests, linters, etc and show the output to GPT so it can fix any issues.
  • Enter a multiline chat message by entering { alone on the first line. End the multiline message with } alone on the last line.
  • If your code is throwing an error, share the error output with GPT using /run or by pasting it into the chat. Let GPT figure out and fix the bug.
  • GPT knows about a lot of standard tools and libraries, but may get some of the fine details wrong about APIs and function arguments. You can paste doc snippets into the chat to resolve these issues.
  • Aider will notice if you launch it on a git repo with uncommitted changes and offer to commit them before proceeding.
  • GPT can only see the content of the files you specifically "add to the chat". Aider also sends GPT-4 a map of your entire git repo. So GPT may ask to see additional files if it feels that's needed for your requests.
  • I also shared some general GPT coding tips on Hacker News.

GPT-4 vs GPT-3.5

Aider supports all of OpenAI's chat models. You can choose a model with the --model command line argument. For a discussion of using other non-OpenAI models, see the FAQ.

You will probably get the best results with one of the GPT-4 models. They have large context windows, better coding skills and they generally obey the instructions in the system prompt. GPT-4 is able to structure code edits as simple "diffs" and use a repository map to improve its ability to make changes in larger codebases.

GPT-3.5 is supported more experimentally and is limited to editing somewhat smaller codebases. It is less able to follow instructions and can't reliably return code edits as "diffs". Aider disables the repository map when using GPT-3.5.

For a detailed and quantitative comparison, please see the code editing benchmark results for GPT-3.5 and GPT-4.

In practice, this means you can use aider to edit a set of source files that total up to the sizes below. Just add the specific set of files to the chat that are relevant to the change you are requesting. This minimizes your use of the context window, as well as costs.

Model Context
Size
Edit
Format
Max
File Size
Max
File Size
Repo
Map?
gpt-3.5-turbo 4k tokens whole file 2k tokens ~8k bytes no
gpt-3.5-turbo-16k 16k tokens whole file 8k tokens ~32k bytes no
gpt-4 8k tokens diffs 8k tokens ~32k bytes yes
gpt-4-32k 32k tokens diffs 32k tokens ~128k bytes yes

Kind words from users

  • "The best AI coding assistant so far." -- Matthew Berman
  • "Aider ... has easily quadrupled my coding productivity." -- SOLAR_FIELDS
  • "What an amazing tool. It's incredible." -- valyagolev
  • "It was WAY faster than I would be getting off the ground and making the first few working versions." -- Daniel Feldman