Merge branch 'main' into gitignore

This commit is contained in:
Paul Gauthier 2023-07-15 10:59:33 -07:00
commit e9806bb84f
5 changed files with 93 additions and 10 deletions

View file

@ -4,6 +4,7 @@
- Support for the OpenAI models in [Azure](https://aider.chat/docs/faq.html#azure)
- Added `--show-repo-map`
- Improved output when retrying connections to the OpenAI API
- Redacted api key from `--verbose` output
- Bugfix: recognize and add files in subdirectories mentioned by user or GPT

View file

@ -3,7 +3,9 @@
`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.
Aider makes it easy to
[git commit, diff & undo changes](https://aider.chat/docs/faq.html#how-does-aider-use-git)
proposed by GPT without copy/pasting.
It also has features that [help GPT-4 understand and modify larger codebases](https://aider.chat/docs/ctags.html).
![aider screencast](assets/screencast.svg)
@ -54,9 +56,10 @@ You can find more chat transcripts on the [examples page](https://aider.chat/exa
## 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.
* GPT can write and edit code in most popular languages: python, javascript, typescript, html, css, etc.
* 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.
* Aider will [automatically commit each changeset to your local git repo](https://aider.chat/docs/faq.html#how-does-aider-use-git) 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](https://aider.chat/docs/ctags.html), 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.
@ -115,7 +118,7 @@ Aider has some ability to help GPT figure out which files to edit all by itself,
* 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.
* [Aider will notice if you launch it on a git repo with uncommitted changes and offer to commit them before proceeding](https://aider.chat/docs/faq.html#how-does-aider-use-git).
* 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](https://aider.chat/docs/ctags.html). 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](https://news.ycombinator.com/item?id=36211879).

View file

@ -622,7 +622,9 @@ class Coder:
requests.exceptions.ConnectionError,
),
max_tries=10,
on_backoff=lambda details: print(f"Retry in {details['wait']} seconds."),
on_backoff=lambda details: print(
f"{details.get('exception','Exception')}\nRetry in {details['wait']:.1f} seconds."
),
)
def send_with_retries(self, model, messages, functions):
kwargs = dict(

View file

@ -1,6 +1,44 @@
# Frequently asked questions
- [How does aider use git?](#how-does-aider-use-git)
- [GPT-4 vs GPT-3.5](#gpt-4-vs-gpt-35)
- [Aider isn't editing my files?](#aider-isnt-editing-my-files)
- [Can I use aider with other LLMs, local LLMs, etc?](#can-i-use-aider-with-other-llms-local-llms-etc)
- [Can I change the system prompts that aider uses?](#can-i-change-the-system-prompts-that-aider-uses)
- [Can I run aider in Google Colab?](#can-i-run-aider-in-google-colab)
## How does aider use git?
It is recommended that you use aider with code that is part of a git repo.
This allows aider to maintain the safety of your code. Using git makes it easy to:
- Review the changes GPT made to your code
- Undo changes that weren't appropriate
- Manage a series of GPT's changes on a git branch
- etc
Working without git means that GPT might drastically change your code without an easy way to undo the changes.
Aider tries to provide safety using git in a few ways:
- It asks to create a git repo if you launch it in a directory without one.
- When you add a file to the chat, aider asks permission to add it to the git repo if needed.
- At launch and before sending requests to GPT, aider checks if the repo is dirty and offers to commit those changes for you. This way, the GPT changes will be applied to a clean repo and won't be intermingled with your own changes.
- After GPT changes your code, aider commits those changes with a descriptive commit message.
Aider also allows you to use in-chat commands to `/diff` or `/undo` the last change made by GPT.
To do more complex management of your git history, you should use `git` on the command line outside of aider.
You can start a branch before using aider to make a sequence of changes.
Or you can `git reset` a longer series of aider changes that didn't pan out. Etc.
While it is not recommended, you can disable aider's use of git in a few ways:
- `--no-auto-commits` will stop aider from git committing each of GPT's changes.
- `--no-dirty-commits` will stop aider from ensuring your repo is clean before sending requests to GPT.
- `--no-git` will completely stop aider from using git on your files. You should ensure you are keeping sensible backups of the files you are working with.
## GPT-4 vs GPT-3.5
Aider supports all of OpenAI's chat models.
@ -38,6 +76,32 @@ This minimizes your use of the context window, as well as costs.
| gpt-4 | 8k tokens | diffs | 8k tokens | ~32k bytes | yes |
| gpt-4-32k | 32k tokens | diffs | 32k tokens | ~128k bytes | yes |
## Aider isn't editing my files?
This usually happens because GPT is not specifying the edits
to make in the format that aider expects.
GPT-3.5 is especially prone to disobeying the system prompt instructions in this manner, but it also happens with GPT-4.
Aider makes every effort to get GPT to conform, and works hard to deal with
replies that are "almost" correctly formatted.
If Aider detects an improperly formatted reply, it gives GPT feedback to try again.
Also, before each release new versions of aider are
[benchmarked](https://aider.chat/docs/benchmarks.html).
This helps prevent regressions in the code editing
performance of GPT that could have been inadvertantly
introduced.
But sometimes GPT just won't cooperate.
In these cases, here are some things you might try:
- Just ask it to try again. Explain the problem with the response if you can. Here is some suggested language which will be familiar to GPT based on its system prompt.
- With GPT-3.5, you could say something like "Send me back the new code as a properly formatted **file listing**".
- With GPT-4, you could say something like "Format those code changes properly as an **edit block**".
- "Don't skip code and replace it with comments, send me back all the code!"
- Etc...
- Use `/drop` to remove files from the chat session which aren't needed for the task at hand. This will reduce distractions and may help GPT produce properly formatted edits.
- Use `/clear` to remove the conversation history, again to help GPT focus.
## Can I use aider with other LLMs, local LLMs, etc?
Aider does not officially support use with LLMs other than OpenAI's gpt-3.5-turbo and gpt-4
@ -98,6 +162,8 @@ and
look like relevant tools to serve local models via a compatible API:
## Can I change the system prompts that aider uses?
Aider is set up to support different system prompts and edit formats

View file

@ -101,14 +101,21 @@ class TestCoder(unittest.TestCase):
# Initialize the Coder object with the mocked IO and mocked repo
coder = Coder.create(models.GPT4, None, mock_io)
fname = Path("file1.txt")
fname.touch()
other_fname = Path("other") / "file1.txt"
other_fname.parent.mkdir(parents=True, exist_ok=True)
other_fname.touch()
mock = MagicMock()
mock.return_value = set(["file1.txt", "other/file1.txt"])
mock.return_value = set([str(fname), str(other_fname)])
coder.get_tracked_files = mock
# Call the check_for_file_mentions method
coder.check_for_file_mentions("Please check file1.txt!")
coder.check_for_file_mentions(f"Please check {fname}!")
self.assertEqual(coder.abs_fnames, set([str(Path("file1.txt").resolve())]))
self.assertEqual(coder.abs_fnames, set([str(fname.resolve())]))
def test_check_for_subdir_mention(self):
# Mock the IO object
@ -117,14 +124,18 @@ class TestCoder(unittest.TestCase):
# Initialize the Coder object with the mocked IO and mocked repo
coder = Coder.create(models.GPT4, None, mock_io)
fname = Path("other") / "file1.txt"
fname.parent.mkdir(parents=True, exist_ok=True)
fname.touch()
mock = MagicMock()
mock.return_value = set(["other/file1.txt"])
mock.return_value = set([str(fname)])
coder.get_tracked_files = mock
# Call the check_for_file_mentions method
coder.check_for_file_mentions("Please check `other/file1.txt`")
coder.check_for_file_mentions(f"Please check `{fname}`")
self.assertEqual(coder.abs_fnames, set([str(Path("other/file1.txt").resolve())]))
self.assertEqual(coder.abs_fnames, set([str(fname.resolve())]))
def test_get_commit_message(self):
# Mock the IO object