Elffuss BraidHub

kikocis/auto-code-rover public

main ยท 15.7 KiBRenderedRawPermalink
1# AutoCodeRover: Autonomous Program Improvement
2
3<br>
4
5<p align="center">
6 <img src="https://github.com/nus-apr/auto-code-rover/assets/16000056/8d249b02-1db4-4f58-a5a4-bdb694d65ab1" alt="autocoderover_logo" width="200px" height="200px">
7</p>
8
9
10<p align="center">
11 <a href="https://arxiv.org/abs/2404.05427"><strong>ArXiv Paper</strong></a>
12 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
13 <a href="https://autocoderover.dev/"><strong>Website</strong></a>
14 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
15 <a href="https://discord.gg/ScXsdE49JY"><strong>Discord server</strong></a>
16</p>
17
18<br>
19
20![overall-workflow](https://github.com/nus-apr/auto-code-rover/assets/48704330/0b8da9ad-588c-4f7d-9c99-53f33d723d35)
21
22<br>
23
24
25> [!NOTE]
26> This is a public version of the AutoCodeRover project. Check the latest results on our [website](https://autocoderover.dev/).
27
28## ๐Ÿ“ฃ Updates
29- [August 14, 2024] On the SWE-bench Verified dataset released by OpenAI, AutoCodeRover(v20240620) achieves **38.40%** efficacy, and AutoCodeRover(v20240408) achieves 28.8% efficacy. More details in the [blog post](https://openai.com/index/introducing-swe-bench-verified/) from OpenAI and [SWE-bench leaderboard](https://www.swebench.com/).
30- [July 18, 2024] AutoCodeRover now supports a new mode that outputs the list of potential fix locations.
31- [June 20, 2024] AutoCodeRover(v20240620) now achieves **30.67%** efficacy (pass@1) on SWE-bench-lite!
32- [June 08, 2024] Added support for Gemini, Groq (thank you [KasaiHarcore](https://github.com/KasaiHarcore) for the contribution!) and Anthropic models through AWS Bedrock (thank you [JGalego](https://github.com/JGalego) for the contribution!).
33- [April 29, 2024] Added support for Claude and Llama models. Find the list of supported models [here](#using-a-different-model)! Support for more models coming soon.
34- [April 19, 2024] AutoCodeRover now supports running on [GitHub issues](#github-issue-mode-set-up-and-run-on-new-github-issues) and [local issues](#local-issue-mode-set-up-and-run-on-local-repositories-and-local-issues)! Feel free to try it out and we welcome your feedback!
35
36## [Discord](https://discord.gg/ScXsdE49JY) - server for general discussion, questions, and feedback.
37
38## ๐Ÿ‘‹ Overview
39
40AutoCodeRover is a fully automated approach for resolving GitHub issues (bug fixing and feature addition) where LLMs are combined with analysis and debugging capabilities to prioritize patch locations ultimately leading to a patch.
41
42[Update on June 20, 2024] AutoCodeRover(v20240620) now resolves **30.67%** of issues (pass@1) in SWE-bench lite! AutoCodeRover achieved this efficacy while being economical - each task costs **less than $0.7** and is completed within **7 mins**!
43
44<p align="center">
45<img src=https://github.com/nus-apr/auto-code-rover/assets/16000056/78d184b2-f15c-4408-9eac-cfd3a11a503a width=500/>
46<img src=https://github.com/nus-apr/auto-code-rover/assets/16000056/83253ae9-8789-474e-942d-708495b5b310 width=500/>
47</p>
48
49[April 08, 2024] First release of AutoCodeRover(v20240408) resolves **19%** of issues in [SWE-bench lite](https://www.swebench.com/lite.html) (pass@1), improving over the current state-of-the-art efficacy of AI software engineers.
50
51
52AutoCodeRover works in two stages:
53
54- ๐Ÿ”Ž Context retrieval: The LLM is provided with code search APIs to navigate the codebase and collect relevant context.
55- ๐Ÿ’Š Patch generation: The LLM tries to write a patch, based on retrieved context.
56
57### โœจ Highlights
58
59AutoCodeRover has two unique features:
60
61- Code search APIs are *Program Structure Aware*. Instead of searching over files by plain string matching, AutoCodeRover searches for relevant code context (methods/classes) in the abstract syntax tree.
62- When a test suite is available, AutoCodeRover can take advantage of test cases to achieve an even higher repair rate, by performing *statistical fault localization*.
63
64## ๐Ÿ—Ž arXiv Paper
65### AutoCodeRover: Autonomous Program Improvement [[arXiv 2404.05427]](https://arxiv.org/abs/2404.05427)
66
67<p align="center">
68 <a href="https://arxiv.org/abs/2404.05427">
69 <img src="https://github.com/nus-apr/auto-code-rover/assets/48704330/c6422951-a6e8-4494-9403-b5ada3d9ee7d" alt="First page of arXiv paper" width="570">
70 </a>
71</p>
72
73For referring to our work, please cite and mention:
74```
75@misc{zhang2024autocoderover,
76 title={AutoCodeRover: Autonomous Program Improvement},
77 author={Yuntong Zhang and Haifeng Ruan and Zhiyu Fan and Abhik Roychoudhury},
78 year={2024},
79 eprint={2404.05427},
80 archivePrefix={arXiv},
81 primaryClass={cs.SE}
82}
83```
84
85## โœ”๏ธ Example: Django Issue #32347
86
87As an example, AutoCodeRover successfully fixed issue [#32347](https://code.djangoproject.com/ticket/32347) of Django. See the demo video for the full process:
88
89https://github.com/nus-apr/auto-code-rover/assets/48704330/719c7a56-40b8-4f3d-a90e-0069e37baad3
90
91### Enhancement: leveraging test cases
92
93AutoCodeRover can resolve even more issues, if test cases are available. See an example in the video:
94
95https://github.com/nus-apr/auto-code-rover/assets/48704330/26c9d5d4-04e0-4b98-be55-61c1d10a36e5
96
97## ๐Ÿš€ Setup & Running
98
99### Setup API key and environment
100
101We recommend running AutoCodeRover in a Docker container.
102
103Set the `OPENAI_KEY` env var to your [OpenAI key](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key):
104
105```
106export OPENAI_KEY=sk-YOUR-OPENAI-API-KEY-HERE
107```
108
109For Anthropic model, Set the `ANTHROPIC_API_KEY` env var can be found [here](https://docs.anthropic.com/claude/reference/getting-started-with-the-api)
110
111```
112export ANTHROPIC_API_KEY=sk-ant-api...
113```
114
115The same with `GROQ_API_KEY`
116
117Build and start the docker image:
118
119```
120docker build -f Dockerfile -t acr .
121docker run -it -e OPENAI_KEY="${OPENAI_KEY:-OPENAI_API_KEY}" -p 3000:3000 -p 5000:5000 acr
122```
123
124Alternatively, you can use `Dockerfile.scratch` which supports arm64 (Apple silicon) and ppc in addition to amd64.
125`Dockerfile.scratch` will build both SWE-bench (from https://github.com/yuntongzhang/SWE-bench.git) and ACR.
126
127```
128docker build -f Dockerfile.scratch -t acr .
129```
130
131There are build args for customizing the build in `Dockerfile.scratch` like this:
132
133```
134docker build --build-arg GIT_EMAIL=your@email.com --build-arg GIT_NAME=your_id \
135 --build-arg SWE_BENCH_REPO=https://github.com/your_id/SWE-bench.git \
136 -f Dockerfile.scratch -t acr .
137```
138
139After setting up, we can run ACR in three modes:
140
1411. GitHub issue mode: Run ACR on a live GitHub issue by providing a link to the issue page.
1422. Local issue mode: Run ACR on a local repository and a file containing the issue description.
1433. SWE-bench mode: Run ACR on SWE-bench task instances.
144
145### [GitHub issue mode] Set up and run on new GitHub issues
146
147If you want to use AutoCodeRover for new GitHub issues in a project, prepare the following:
148
149- Link to clone the project (used for `git clone ...`).
150- Commit hash of the project version for AutoCodeRover to work on (used for `git checkout ...`).
151- Link to the GitHub issue page.
152
153Then, in the docker container (or your local copy of AutoCodeRover), run the following commands to set up the target project
154and generate patch:
155
156```
157cd /opt/auto-code-rover
158conda activate auto-code-rover
159PYTHONPATH=. python app/main.py github-issue --output-dir output --setup-dir setup --model gpt-4o-2024-05-13 --model-temperature 0.2 --task-id <task id> --clone-link <link for cloning the project> --commit-hash <any version that has the issue> --issue-link <link to issue page>
160```
161Here is an example command for running ACR on an issue from the langchain GitHub issue tracker:
162
163```
164PYTHONPATH=. python app/main.py github-issue --output-dir output --setup-dir setup --model gpt-4o-2024-05-13 --model-temperature 0.2 --task-id langchain-20453 --clone-link https://github.com/langchain-ai/langchain.git --commit-hash cb6e5e5 --issue-link https://github.com/langchain-ai/langchain/issues/20453
165```
166
167The `<task id>` can be any string used to identify this issue.
168
169If patch generation is successful, the path to the generated patch will be printed in the end.
170
171Web UI is also provided for visualization of the issue fixing process.
172In the docker shell, run the following command:
173
174```bash
175cd /opt/auto-code-rover/demo_vis/
176bash run.sh
177```
178
179then open the url `localhost:3000` in the web explorer.
180
181
182### [Local issue mode] Set up and run on local repositories and local issues
183
184Instead of cloning a remote project and run ACR on an online issue, you can also prepare the local repository and issue beforehand,
185if that suits the use case.
186
187For running ACR on a local issue and local codebase, prepare a local codebase and write an issue description into a file,
188and run the following commands:
189
190```
191cd /opt/auto-code-rover
192conda activate auto-code-rover
193PYTHONPATH=. python app/main.py local-issue --output-dir output --model gpt-4o-2024-05-13 --model-temperature 0.2 --task-id <task id> --local-repo <path to the local project repository> --issue-file <path to the file containing issue description>
194```
195
196If patch generation is successful, the path to the generated patch will be printed in the end.
197
198
199### [SWE-bench mode] Set up and run on SWE-bench tasks
200
201This mode is for running ACR on existing issue tasks contained in SWE-bench.
202
203#### Set up
204
205In the docker container, we need to first set up the tasks to run in SWE-bench (e.g., `django__django-11133`). The list of all tasks can be found in [`conf/swe_lite_tasks.txt`](conf/swe_lite_tasks.txt).
206
207The tasks need to be put in a file, one per line:
208
209```
210cd /opt/SWE-bench
211echo django__django-11133 > tasks.txt
212```
213
214Or if running on arm64 (e.g. Apple silicon), try this one which doesn't depend on Python 3.6 (which isn't supported in this env):
215
216```
217echo django__django-16041 > tasks.txt
218```
219
220Then, set up these tasks by running:
221
222```
223cd /opt/SWE-bench
224conda activate swe-bench
225python harness/run_setup.py --log_dir logs --testbed testbed --result_dir setup_result --subset_file tasks.txt
226```
227
228Once the setup for this task is completed, the following two lines will be printed:
229
230```
231setup_map is saved to setup_result/setup_map.json
232tasks_map is saved to setup_result/tasks_map.json
233```
234
235The `testbed` directory will now contain the cloned source code of the target project.
236A conda environment will also be created for this task instance.
237
238_If you want to set up multiple tasks together, put their ids in `tasks.txt` and follow the same steps._
239
240#### Run a single task in SWE-bench
241
242Before running the task (`django__django-11133` here), make sure it has been set up as mentioned [above](#set-up-one-or-more-tasks-in-swe-bench).
243
244```
245cd /opt/auto-code-rover
246conda activate auto-code-rover
247PYTHONPATH=. python app/main.py swe-bench --model gpt-4o-2024-05-13 --setup-map ../SWE-bench/setup_result/setup_map.json --tasks-map ../SWE-bench/setup_result/tasks_map.json --output-dir output --task django__django-11133
248```
249
250The output of the run can then be found in `output/`. For example, the patch generated for `django__django-11133` can be found at a location like this: `output/applicable_patch/django__django-11133_yyyy-MM-dd_HH-mm-ss/extracted_patch_1.diff` (the date-time field in the directory name will be different depending on when the experiment was run).
251
252#### Run multiple tasks in SWE-bench
253
254First, put the id's of all tasks to run in a file, one per line. Suppose this file is `tasks.txt`, the tasks can be run with
255
256```
257cd /opt/auto-code-rover
258conda activate auto-code-rover
259PYTHONPATH=. python app/main.py swe-bench --model gpt-4o-2024-05-13 --setup-map ../SWE-bench/setup_result/setup_map.json --tasks-map ../SWE-bench/setup_result/tasks_map.json --output-dir output --task-list-file /opt/SWE-bench/tasks.txt
260```
261
262**NOTE**: make sure that the tasks in `tasks.txt` have all been set up in SWE-bench. See the steps [above](#set-up-one-or-more-tasks-in-swe-bench).
263
264#### Using a config file
265
266Alternatively, a config file can be used to specify all parameters and tasks to run. See `conf/vanilla-lite.conf` for an example.
267Also see [EXPERIMENT.md](EXPERIMENT.md) for the details of the items in a conf file.
268A config file can be used by:
269
270```
271python scripts/run.py conf/vanilla-lite.conf
272```
273
274### Using a different model
275
276AutoCodeRover works with different foundation models. You can set the foundation model to be used with the `--model` command line argument.
277
278The current list of supported models:
279
280| | Model | AutoCodeRover cmd line argument |
281|:--------------:|---------------|--------------|
282| OpenAI | gpt-4o-2024-08-06 | --model gpt-4o-2024-08-06 |
283| | gpt-4o-2024-05-13 | --model gpt-4o-2024-05-13 |
284| | gpt-4-turbo-2024-04-09 | --model gpt-4-turbo-2024-04-09 |
285| | gpt-4-0125-preview | --model gpt-4-0125-preview |
286| | gpt-4-1106-preview | --model gpt-4-1106-preview |
287| | gpt-3.5-turbo-0125 | --model gpt-3.5-turbo-0125 |
288| | gpt-3.5-turbo-1106 | --model gpt-3.5-turbo-1106 |
289| | gpt-3.5-turbo-16k-0613 | --model gpt-3.5-turbo-16k-0613 |
290| | gpt-3.5-turbo-0613 | --model gpt-3.5-turbo-0613 |
291| | gpt-4-0613 | --model gpt-4-0613 |
292| Anthropic | Claude 3.5 Sonnet | --model claude-3-5-sonnet-20240620 |
293| | Claude 3 Opus | --model claude-3-opus-20240229 |
294| | Claude 3 Sonnet | --model claude-3-sonnet-20240229 |
295| | Claude 3 Haiku | --model claude-3-haiku-20240307 |
296| Meta | Llama 3 70B | --model llama3:70b |
297| | Llama 3 8B | --model llama3 |
298| AWS | Claude 3 Opus | --model bedrock/anthropic.claude-3-opus-20240229-v1:0 |
299| | Claude 3 Sonnet | --model bedrock/anthropic.claude-3-sonnet-20240229-v1:0 |
300| | Claude 3 Haiku | --model bedrock/anthropic.claude-3-haiku-20240307-v1:0 |
301| Groq | Llama 3 8B | --model groq/llama3-8b-8192 |
302| | Llama 3 70B | --model groq/llama3-70b-8192 |
303| | Llama 2 70B | --model groq/llama2-70b-4096 |
304| | Mixtral 8x7B | --model groq/mixtral-8x7b-32768 |
305| | Gemma 7B | --model groq/gemma-7b-it |
306
307
308> [!NOTE]
309> Using the Groq models on a free plan can cause the context limit to be exceeded, even on simple issues.
310
311> [!NOTE]
312> Some notes on running ACR with local models such as llama3:
313> 1. Before using the llama3 models, please [install ollama](https://ollama.com/download/linux) and download the corresponding models with ollama (e.g. `ollama pull llama3`).
314> 2. You can run ollama server on the host machine, and ACR in its container. ACR will attempt to communicate to the ollama server on host.
315> 3. If your setup is ollama in host + ACR in its container, we recommend installing [Docker Desktop](https://docs.docker.com/desktop/) on the host, in addition to the [Docker Engine](https://docs.docker.com/engine/).
316> - Docker Desktop contains Docker Engine, and also has a virtual machine which makes it easier to access the host ports from within a container. With Docker Desktop, this setup will work without additional effort.
317> - When the docker installation is only Docker Engine, you may need to add either `--net=host` or `--add-host host.docker.internal=host-gateway` to the `docker run` command when starting the ACR container, so that ACR can communicate with the ollama server on the host machine.
318
319
320## Experiment Replication
321
322Please refer to [EXPERIMENT.md](EXPERIMENT.md) for information on experiment replication.
323
324## โœ‰๏ธ Contacts
325
326For any queries, you are welcome to open an issue.
327
328Alternatively, contact us at: {[yuntong](https://yuntongzhang.github.io/),[hruan](https://www.linkedin.com/in/haifeng-ruan-701a731a4/),[zhiyufan](https://zhiyufan.github.io/)}@comp.nus.edu.sg.
329
330## Acknowledgements
331
332This work was partially supported by a Singapore Ministry of Education (MoE) Tier 3 grant "Automated Program Repair", MOE-MOET32021-0001.