Elffuss BraidHub

kikocis/auto-code-rover public

0f4e2e4e2ecb ยท 11.9 KiBRenderedRawPermalink
1# AutoCodeRover: Autonomous Program Improvement
2
3![overall-workflow](https://github.com/nus-apr/auto-code-rover/assets/48704330/0b8da9ad-588c-4f7d-9c99-53f33d723d35)
4
5<p align="center">
6 <a href="https://arxiv.org/abs/2404.05427"><strong>ArXiv Paper</strong></a>
7</p>
8
9
10## ๐Ÿ“ฃ Updates
11
12- [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.
13- [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!
14
15## ๐Ÿ‘‹ Overview
16
17AutoCodeRover 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.
18
19AutoCodeRover resolves ~**16%** of issues of [SWE-bench](https://www.swebench.com) (total 2294 GitHub issues) and ~**22%** issues of [SWE-bench lite](https://www.swebench.com/lite.html) (total 300 GitHub issues), improving over the current state-of-the-art efficacy of AI software engineers.
20
21<p align="center">
22<img src=https://github.com/nus-apr/auto-code-rover/assets/48704330/e10c3270-442c-4673-8656-735c892dfb66 width=500/>
23</p>
24
25AutoCodeRover works in two stages:
26
27- ๐Ÿ”Ž Context retrieval: The LLM is provided with code search APIs to navigate the codebase and collect relevant context.
28- ๐Ÿ’Š Patch generation: The LLM tries to write a patch, based on retrieved context.
29
30### โœจ Highlights
31
32AutoCodeRover has two unique features:
33
34- 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.
35- 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*.
36
37## ๐Ÿ—Ž arXiv Paper
38### AutoCodeRover: Autonomous Program Improvement [[arXiv 2404.05427]](https://arxiv.org/abs/2404.05427)
39
40<p align="center">
41 <a href="https://arxiv.org/abs/2404.05427">
42 <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">
43 </a>
44</p>
45
46For referring to our work, please cite and mention:
47```
48@misc{zhang2024autocoderover,
49 title={AutoCodeRover: Autonomous Program Improvement},
50 author={Yuntong Zhang and Haifeng Ruan and Zhiyu Fan and Abhik Roychoudhury},
51 year={2024},
52 eprint={2404.05427},
53 archivePrefix={arXiv},
54 primaryClass={cs.SE}
55}
56```
57
58## โœ”๏ธ Example: Django Issue #32347
59
60As an example, AutoCodeRover successfully fixed issue [#32347](https://code.djangoproject.com/ticket/32347) of Django. See the demo video for the full process:
61
62https://github.com/nus-apr/auto-code-rover/assets/48704330/719c7a56-40b8-4f3d-a90e-0069e37baad3
63
64### Enhancement: leveraging test cases
65
66AutoCodeRover can resolve even more issues, if test cases are available. See an example in the video:
67
68https://github.com/nus-apr/auto-code-rover/assets/48704330/26c9d5d4-04e0-4b98-be55-61c1d10a36e5
69
70## ๐Ÿš€ Setup & Running
71
72### Setup API key and environment
73
74We recommend running AutoCodeRover in a Docker container.
75
76Set the `OPENAI_KEY` env var to your [OpenAI key](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key):
77
78```
79export OPENAI_KEY=sk-YOUR-OPENAI-API-KEY-HERE
80```
81(Alternatively, if you want to use Anthropic models instead, set `ANTHROPIC_API_KEY`.)
82
83Build and start the docker image:
84
85```
86docker build -f Dockerfile -t acr .
87docker run -it -e OPENAI_KEY="${OPENAI_KEY:-OPENAI_API_KEY}" -p 3000:3000 -p 5000:5000 acr
88```
89
90Alternatively, you can use `Dockerfile.scratch` which supports arm64 (Apple silicon) and ppc in addition to amd64.
91`Dockerfile.scratch` will build both SWE-bench (from https://github.com/yuntongzhang/SWE-bench.git) and ACR.
92
93```
94docker build -f Dockerfile.scratch -t acr .
95```
96
97There are build args for customizing the build in `Dockerfile.scratch` like this:
98
99```
100docker build --build-arg GIT_EMAIL=your@email.com --build-arg GIT_NAME=your_id \
101 --build-arg SWE_BENCH_REPO=https://github.com/your_id/SWE-bench.git \
102 -f Dockerfile.scratch -t acr .
103```
104
105After setting up, we can run ACR in three modes:
106
1071. GitHub issue mode: Run ACR on a live GitHub issue by providing a link to the issue page.
1082. Local issue mode: Run ACR on a local repository and a file containing the issue description.
1093. SWE-bench mode: Run ACR on SWE-bench task instances.
110
111### [GitHub issue mode] Set up and run on new GitHub issues
112
113If you want to use AutoCodeRover for new GitHub issues in a project, prepare the following:
114
115- Link to clone the project (used for `git clone ...`).
116- Commit hash of the project version for AutoCodeRover to work on (used for `git checkout ...`).
117- Link to the GitHub issue page.
118
119Then, in the docker container (or your local copy of AutoCodeRover), run the following commands to set up the target project
120and generate patch:
121
122```
123cd /opt/auto-code-rover
124conda activate auto-code-rover
125PYTHONPATH=. 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>
126```
127Here is an example command for running ACR on an issue from the langchain GitHub issue tracker:
128
129```
130PYTHONPATH=. 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
131```
132
133The `<task id>` can be any string used to identify this issue.
134
135If patch generation is successful, the path to the generated patch will be printed in the end.
136
137Web UI is also provided for visualization of the issue fixing process.
138In the docker shell, run the following command:
139
140```bash
141cd /opt/auto-code-rover/demo_vis/
142bash run.sh
143```
144
145then open the url `localhost:3000` in the web explorer.
146
147
148### [Local issue mode] Set up and run on local repositories and local issues
149
150Instead of cloning a remote project and run ACR on an online issue, you can also prepare the local repository and issue beforehand,
151if that suits the use case.
152
153For running ACR on a local issue and local codebase, prepare a local codebase and write an issue description into a file,
154and run the following commands:
155
156```
157cd /opt/auto-code-rover
158conda activate auto-code-rover
159PYTHONPATH=. 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>
160```
161
162If patch generation is successful, the path to the generated patch will be printed in the end.
163
164
165### [SWE-bench mode] Set up and run on SWE-bench tasks
166
167This mode is for running ACR on existing issue tasks contained in SWE-bench.
168
169#### Set up
170
171In 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).
172
173The tasks need to be put in a file, one per line:
174
175```
176cd /opt/SWE-bench
177echo django__django-11133 > tasks.txt
178```
179
180Or 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):
181
182```
183echo django__django-16041 > tasks.txt
184```
185
186Then, set up these tasks by running:
187
188```
189cd /opt/SWE-bench
190conda activate swe-bench
191python harness/run_setup.py --log_dir logs --testbed testbed --result_dir setup_result --subset_file tasks.txt
192```
193
194Once the setup for this task is completed, the following two lines will be printed:
195
196```
197setup_map is saved to setup_result/setup_map.json
198tasks_map is saved to setup_result/tasks_map.json
199```
200
201The `testbed` directory will now contain the cloned source code of the target project.
202A conda environment will also be created for this task instance.
203
204_If you want to set up multiple tasks together, put their ids in `tasks.txt` and follow the same steps._
205
206#### Run a single task in SWE-bench
207
208Before 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).
209
210```
211cd /opt/auto-code-rover
212conda activate auto-code-rover
213PYTHONPATH=. 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
214```
215
216The 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).
217
218#### Run multiple tasks in SWE-bench
219
220First, 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
221
222```
223cd /opt/auto-code-rover
224conda activate auto-code-rover
225PYTHONPATH=. 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
226```
227
228**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).
229
230#### Using a config file
231
232Alternatively, a config file can be used to specify all parameters and tasks to run. See `conf/vanilla-lite.conf` for an example.
233Also see [EXPERIMENT.md](EXPERIMENT.md) for the details of the items in a conf file.
234A config file can be used by:
235
236```
237python scripts/run.py conf/vanilla-lite.conf
238```
239
240### Using a different model
241
242AutoCodeRover works with different foundation models. You can set the foundation model to be used with the `--model` command line argument.
243
244The current list of supported models:
245
246| | Model | AutoCodeRover cmd line argument |
247|:--------------:|---------------|--------------|
248| OpenAI | gpt-4-turbo-2024-04-09 | --model gpt-4-turbo-2024-04-09 |
249| | gpt-4-0125-preview | --model gpt-4-0125-preview |
250| | gpt-4-1106-preview | --model gpt-4-1106-preview |
251| | gpt-3.5-turbo-0125 | --model gpt-3.5-turbo-0125 |
252| | gpt-3.5-turbo-1106 | --model gpt-3.5-turbo-1106 |
253| | gpt-3.5-turbo-16k-0613 | --model gpt-3.5-turbo-16k-0613 |
254| | gpt-3.5-turbo-0613 | --model gpt-3.5-turbo-0613 |
255| | gpt-4-0613 | --model gpt-4-0613 |
256| Anthropic | Claude 3 Opus | --model claude-3-opus-20240229 |
257| | Claude 3 Sonnet | --model claude-3-sonnet-20240229 |
258| | Claude 3 Haiku | --model claude-3-haiku-20240307 |
259| Meta | Llama 3 70B | --model llama3:70b |
260| | Llama 3 8B | --model llama3 |
261
262Before using the llama models, please [install ollama](https://ollama.com/download/linux) and download the corresponding models with ollama (e.g. `ollama pull llama3`).
263
264## Experiment Replication
265
266Please refer to [EXPERIMENT.md](EXPERIMENT.md) for information on experiment replication.
267
268## โœ‰๏ธ Contacts
269
270For any queries, you are welcome to open an issue.
271
272Alternatively, 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.
273
274## Acknowledgements
275
276This work was partially supported by a Singapore Ministry of Education (MoE) Tier 3 grant "Automated Program Repair", MOE-MOET32021-0001.