From e6996da018e2e8ae26ff4644e68f0857210c5e54 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 14 Jul 2023 20:28:33 -0700 Subject: [PATCH 1/9] fix tests for windows --- tests/test_coder.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/test_coder.py b/tests/test_coder.py index 01c90e4a3..445aab345 100644 --- a/tests/test_coder.py +++ b/tests/test_coder.py @@ -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 From 9d9de4d02ef94ac5868cfcad545bd301ce9c793e Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 14 Jul 2023 21:16:18 -0700 Subject: [PATCH 2/9] added git faq --- docs/faq.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/faq.md b/docs/faq.md index 49c63645c..fc1e6b8d9 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -1,6 +1,36 @@ # Frequently asked questions +## 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 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. + - Before sending requests to GPT, it 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. + +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're working with. + + ## GPT-4 vs GPT-3.5 Aider supports all of OpenAI's chat models. From 843c51c35e5178509135dc0bde8f010ffbb3ab4b Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 14 Jul 2023 21:21:00 -0700 Subject: [PATCH 3/9] copy --- docs/faq.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/faq.md b/docs/faq.md index fc1e6b8d9..b4218cb0f 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -6,9 +6,9 @@ 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 GPT's changes on a git branch + - 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. @@ -16,19 +16,19 @@ Working without git means that GPT might drastically change your code without an 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. - - Before sending requests to GPT, it 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. + - 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. +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're working with. + - `--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 From 9f7f6607c227ff7c5ff0a966793651edc3ce48d5 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 14 Jul 2023 21:22:49 -0700 Subject: [PATCH 4/9] copy --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 637173f5e..5d4b62dff 100644 --- a/README.md +++ b/README.md @@ -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) @@ -56,7 +58,7 @@ You can find more chat transcripts on the [examples page](https://aider.chat/exa * 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. +* 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 +117,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). From 1b10751585c465d036830c468c77816bdc07f8c5 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 15 Jul 2023 10:19:48 -0700 Subject: [PATCH 5/9] More informative retry messages --- aider/coders/base_coder.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 46d325f31..f4b000acf 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -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( From 8622ffaf4c74e9e1799d645cc18d1666b38297bb Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 15 Jul 2023 10:34:55 -0700 Subject: [PATCH 6/9] Added faq entry --- docs/faq.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/faq.md b/docs/faq.md index b4218cb0f..891003095 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -16,6 +16,7 @@ Working without git means that GPT might drastically change your code without an 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. @@ -68,6 +69,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 @@ -128,6 +155,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 From 7a2c954eb7b381fd294e399e219153e3eac70c98 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 15 Jul 2023 10:36:02 -0700 Subject: [PATCH 7/9] Updated HISTORY --- HISTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/HISTORY.md b/HISTORY.md index fd16b0e0d..22b4ee8ba 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -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 From adf123c30e5e5e46c315a888c350bbba548f2a71 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 15 Jul 2023 10:53:12 -0700 Subject: [PATCH 8/9] aider: Added table of contents to the `faq.md` file. # Aider chat conversation: USER: add a table of contents ASSISTANT: To add a table of contents to the `faq.md` file, we need to add a list of links to the sections at the top of the file. Each link should be in the format `[Section Name](#section-name)`, where `Section Name` is the name of the section and `section-name` is the section name in lowercase with spaces replaced by hyphens. Here is the *edit block* for this change: markdown docs/faq.md <<<<<<< ORIGINAL # Frequently asked questions ## How does aider use git? ======= # 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? >>>>>>> UPDATED --- docs/faq.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/faq.md b/docs/faq.md index 891003095..8bcd28a59 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -1,6 +1,13 @@ # 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. From 9785ede9602591e22e0d9339571c23e5e0b81849 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 15 Jul 2023 10:59:16 -0700 Subject: [PATCH 9/9] copy --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5d4b62dff..729996741 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ 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](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.