Elffuss BraidHub

kikocis/auto-code-rover public

831d2a8f2ea0 ยท 15.2 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- [July 18, 2024] Added support for fix localization output mode and requirements.txt
30- [June 20, 2024] AutoCodeRover now achieves **30.67%** efficacy (pass@1) on SWE-bench-lite!
31- [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!).
32- [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.
33- [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!
34
35## [Discord](https://discord.gg/ScXsdE49JY) - server for general discussion, questions, and feedback.
36
37## ๐Ÿ‘‹ Overview
38
39AutoCodeRover 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.
40
41[Update on June 20, 2024] AutoCodeRover 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**!
42
43<p align="center">
44<img src=https://github.com/nus-apr/auto-code-rover/assets/16000056/78d184b2-f15c-4408-9eac-cfd3a11a503a width=500/>
45<img src=https://github.com/nus-apr/auto-code-rover/assets/16000056/83253ae9-8789-474e-942d-708495b5b310 width=500/>
46</p>
47
48[April 08, 2024] First release of AutoCodeRover 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.
49
50
51AutoCodeRover works in two stages:
52
53- ๐Ÿ”Ž Context retrieval: The LLM is provided with code search APIs to navigate the codebase and collect relevant context.
54- ๐Ÿ’Š Patch generation: The LLM tries to write a patch, based on retrieved context.
55
56### โœจ Highlights
57
58AutoCodeRover has two unique features:
59
60- 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.
61- 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*.
62
63## ๐Ÿ—Ž arXiv Paper
64### AutoCodeRover: Autonomous Program Improvement [[arXiv 2404.05427]](https://arxiv.org/abs/2404.05427)
65
66<p align="center">
67 <a href="https://arxiv.org/abs/2404.05427">
68 <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">
69 </a>
70</p>
71
72For referring to our work, please cite and mention:
73```
74@misc{zhang2024autocoderover,
75 title={AutoCodeRover: Autonomous Program Improvement},
76 author={Yuntong Zhang and Haifeng Ruan and Zhiyu Fan and Abhik Roychoudhury},
77 year={2024},
78 eprint={2404.05427},
79 archivePrefix={arXiv},
80 primaryClass={cs.SE}
81}
82```
83
84## โœ”๏ธ Example: Django Issue #32347
85
86As an example, AutoCodeRover successfully fixed issue [#32347](https://code.djangoproject.com/ticket/32347) of Django. See the demo video for the full process:
87
88https://github.com/nus-apr/auto-code-rover/assets/48704330/719c7a56-40b8-4f3d-a90e-0069e37baad3
89
90### Enhancement: leveraging test cases
91
92AutoCodeRover can resolve even more issues, if test cases are available. See an example in the video:
93
94https://github.com/nus-apr/auto-code-rover/assets/48704330/26c9d5d4-04e0-4b98-be55-61c1d10a36e5
95
96## ๐Ÿš€ Setup & Running
97
98### Setup API key and environment
99
100We recommend running AutoCodeRover in a Docker container.
101
102Set the `OPENAI_KEY` env var to your [OpenAI key](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key):
103
104```
105export OPENAI_KEY=sk-YOUR-OPENAI-API-KEY-HERE
106```
107
108For Anthropic model, Set the `ANTHROPIC_API_KEY` env var can be found [here](https://docs.anthropic.com/claude/reference/getting-started-with-the-api)
109
110```
111export ANTHROPIC_API_KEY=sk-ant-api...
112```
113
114The same with `GROQ_API_KEY`
115
116Build and start the docker image:
117
118```
119docker build -f Dockerfile -t acr .
120docker run -it -e OPENAI_KEY="${OPENAI_KEY:-OPENAI_API_KEY}" -p 3000:3000 -p 5000:5000 acr
121```
122
123Alternatively, you can use `Dockerfile.scratch` which supports arm64 (Apple silicon) and ppc in addition to amd64.
124`Dockerfile.scratch` will build both SWE-bench (from https://github.com/yuntongzhang/SWE-bench.git) and ACR.
125
126```
127docker build -f Dockerfile.scratch -t acr .
128```
129
130There are build args for customizing the build in `Dockerfile.scratch` like this:
131
132```
133docker build --build-arg GIT_EMAIL=your@email.com --build-arg GIT_NAME=your_id \
134 --build-arg SWE_BENCH_REPO=https://github.com/your_id/SWE-bench.git \
135 -f Dockerfile.scratch -t acr .
136```
137
138After setting up, we can run ACR in three modes:
139
1401. GitHub issue mode: Run ACR on a live GitHub issue by providing a link to the issue page.
1412. Local issue mode: Run ACR on a local repository and a file containing the issue description.
1423. SWE-bench mode: Run ACR on SWE-bench task instances.
143
144### [GitHub issue mode] Set up and run on new GitHub issues
145
146If you want to use AutoCodeRover for new GitHub issues in a project, prepare the following:
147
148- Link to clone the project (used for `git clone ...`).
149- Commit hash of the project version for AutoCodeRover to work on (used for `git checkout ...`).
150- Link to the GitHub issue page.
151
152Then, in the docker container (or your local copy of AutoCodeRover), run the following commands to set up the target project
153and generate patch:
154
155```
156cd /opt/auto-code-rover
157conda activate auto-code-rover
158PYTHONPATH=. python app/main.py github-issue --output-dir output --setup-dir setup --model gpt-4-0125-preview --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>
159```
160Here is an example command for running ACR on an issue from the langchain GitHub issue tracker:
161
162```
163PYTHONPATH=. python app/main.py github-issue --output-dir output --setup-dir setup --model gpt-4-0125-preview --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
164```
165
166The `<task id>` can be any string used to identify this issue.
167
168If patch generation is successful, the path to the generated patch will be printed in the end.
169
170Web UI is also provided for visualization of the issue fixing process.
171In the docker shell, run the following command:
172
173```bash
174cd /opt/auto-code-rover/demo_vis/
175bash run.sh
176```
177
178then open the url `localhost:3000` in the web explorer.
179
180
181### [Local issue mode] Set up and run on local repositories and local issues
182
183Instead of cloning a remote project and run ACR on an online issue, you can also prepare the local repository and issue beforehand,
184if that suits the use case.
185
186For running ACR on a local issue and local codebase, prepare a local codebase and write an issue description into a file,
187and run the following commands:
188
189```
190cd /opt/auto-code-rover
191conda activate auto-code-rover
192PYTHONPATH=. python app/main.py local-issue --output-dir output --model gpt-4-0125-preview --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>
193```
194
195If patch generation is successful, the path to the generated patch will be printed in the end.
196
197
198### [SWE-bench mode] Set up and run on SWE-bench tasks
199
200This mode is for running ACR on existing issue tasks contained in SWE-bench.
201
202#### Set up
203
204In 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).
205
206The tasks need to be put in a file, one per line:
207
208```
209cd /opt/SWE-bench
210echo django__django-11133 > tasks.txt
211```
212
213Or 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):
214
215```
216echo django__django-16041 > tasks.txt
217```
218
219Then, set up these tasks by running:
220
221```
222cd /opt/SWE-bench
223conda activate swe-bench
224python harness/run_setup.py --log_dir logs --testbed testbed --result_dir setup_result --subset_file tasks.txt
225```
226
227Once the setup for this task is completed, the following two lines will be printed:
228
229```
230setup_map is saved to setup_result/setup_map.json
231tasks_map is saved to setup_result/tasks_map.json
232```
233
234The `testbed` directory will now contain the cloned source code of the target project.
235A conda environment will also be created for this task instance.
236
237_If you want to set up multiple tasks together, put their ids in `tasks.txt` and follow the same steps._
238
239#### Run a single task in SWE-bench
240
241Before 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).
242
243```
244cd /opt/auto-code-rover
245conda activate auto-code-rover
246PYTHONPATH=. python app/main.py swe-bench --model gpt-4-0125-preview --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
247```
248
249The 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).
250
251#### Run multiple tasks in SWE-bench
252
253First, 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
254
255```
256cd /opt/auto-code-rover
257conda activate auto-code-rover
258PYTHONPATH=. python app/main.py swe-bench --model gpt-4-0125-preview --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
259```
260
261**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).
262
263#### Using a config file
264
265Alternatively, a config file can be used to specify all parameters and tasks to run. See `conf/vanilla-lite.conf` for an example.
266Also see [EXPERIMENT.md](EXPERIMENT.md) for the details of the items in a conf file.
267A config file can be used by:
268
269```
270python scripts/run.py conf/vanilla-lite.conf
271```
272
273### Using a different model
274
275AutoCodeRover works with different foundation models. You can set the foundation model to be used with the `--model` command line argument.
276
277The current list of supported models:
278
279| | Model | AutoCodeRover cmd line argument |
280|:--------------:|---------------|--------------|
281| OpenAI | gpt-4-turbo-2024-04-09 | --model gpt-4-turbo-2024-04-09 |
282| | gpt-4-0125-preview | --model gpt-4-0125-preview |
283| | gpt-4-1106-preview | --model gpt-4-1106-preview |
284| | gpt-3.5-turbo-0125 | --model gpt-3.5-turbo-0125 |
285| | gpt-3.5-turbo-1106 | --model gpt-3.5-turbo-1106 |
286| | gpt-3.5-turbo-16k-0613 | --model gpt-3.5-turbo-16k-0613 |
287| | gpt-3.5-turbo-0613 | --model gpt-3.5-turbo-0613 |
288| | gpt-4-0613 | --model gpt-4-0613 |
289| Anthropic | Claude 3.5 Sonnet | --model claude-3-5-sonnet-20240620 |
290| | Claude 3 Opus | --model claude-3-opus-20240229 |
291| | Claude 3 Sonnet | --model claude-3-sonnet-20240229 |
292| | Claude 3 Haiku | --model claude-3-haiku-20240307 |
293| Meta | Llama 3 70B | --model llama3:70b |
294| | Llama 3 8B | --model llama3 |
295| AWS | Claude 3 Opus | --model bedrock/anthropic.claude-3-opus-20240229-v1:0 |
296| | Claude 3 Sonnet | --model bedrock/anthropic.claude-3-sonnet-20240229-v1:0 |
297| | Claude 3 Haiku | --model bedrock/anthropic.claude-3-haiku-20240307-v1:0 |
298| Groq | Llama 3 8B | --model groq/llama3-8b-8192 |
299| | Llama 3 70B | --model groq/llama3-70b-8192 |
300| | Llama 2 70B | --model groq/llama2-70b-4096 |
301| | Mixtral 8x7B | --model groq/mixtral-8x7b-32768 |
302| | Gemma 7B | --model groq/gemma-7b-it |
303
304
305> [!NOTE]
306> Using the Groq models on a free plan can cause the context limit to be exceeded, even on simple issues.
307
308> [!NOTE]
309> Some notes on running ACR with local models such as llama3:
310> 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`).
311> 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.
312> 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/).
313> - 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.
314> - 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.
315
316
317## Experiment Replication
318
319Please refer to [EXPERIMENT.md](EXPERIMENT.md) for information on experiment replication.
320
321## โœ‰๏ธ Contacts
322
323For any queries, you are welcome to open an issue.
324
325Alternatively, 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.
326
327## Acknowledgements
328
329This work was partially supported by a Singapore Ministry of Education (MoE) Tier 3 grant "Automated Program Repair", MOE-MOET32021-0001.