kikocis/auto-code-rover public
Changesets · Branches · Tags · Compare
| Changeset | a6e372ee0e4aa6ad9c9211deff241725852d75b38c89ee26e976355fffc119b4 |
|---|---|
| Author | Zhang Yuntong <ang.unong@gmail.com> · 2024-08-09 11:52 +08:00 |
| Committer | Zhang Yuntong <ang.unong@gmail.com> · 2024-08-09 11:52 +08:00 |
| Parents | 0cb0fe7a2cd9 |
8 files changed
modified Dockerfile.minimal +2 −0
| @@ -9,5 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | COPY . /opt/auto-code-rover |
| 11 | 11 | |
| 12 | +ENV PYTHONPATH=/opt/auto-code-rover | |
| 13 | + | |
| 12 | 14 | WORKDIR /opt/auto-code-rover |
| 13 | 15 | RUN conda env create -f environment.yml |
modified README.md +8 −6
| @@ -155,12 +155,12 @@ | ||
| 155 | 155 | ``` |
| 156 | 156 | cd /opt/auto-code-rover |
| 157 | 157 | conda activate auto-code-rover |
| 158 | -PYTHONPATH=. 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> | |
| 158 | +PYTHONPATH=. 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> | |
| 159 | 159 | ``` |
| 160 | 160 | Here is an example command for running ACR on an issue from the langchain GitHub issue tracker: |
| 161 | 161 | |
| 162 | 162 | ``` |
| 163 | -PYTHONPATH=. 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 | |
| 163 | +PYTHONPATH=. 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 | |
| 164 | 164 | ``` |
| 165 | 165 | |
| 166 | 166 | The `<task id>` can be any string used to identify this issue. |
| @@ -189,7 +189,7 @@ | ||
| 189 | 189 | ``` |
| 190 | 190 | cd /opt/auto-code-rover |
| 191 | 191 | conda activate auto-code-rover |
| 192 | -PYTHONPATH=. 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> | |
| 192 | +PYTHONPATH=. 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> | |
| 193 | 193 | ``` |
| 194 | 194 | |
| 195 | 195 | If patch generation is successful, the path to the generated patch will be printed in the end. |
| @@ -243,7 +243,7 @@ | ||
| 243 | 243 | ``` |
| 244 | 244 | cd /opt/auto-code-rover |
| 245 | 245 | conda activate auto-code-rover |
| 246 | -PYTHONPATH=. 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 | |
| 246 | +PYTHONPATH=. 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 | |
| 247 | 247 | ``` |
| 248 | 248 | |
| 249 | 249 | The 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). |
| @@ -255,7 +255,7 @@ | ||
| 255 | 255 | ``` |
| 256 | 256 | cd /opt/auto-code-rover |
| 257 | 257 | conda activate auto-code-rover |
| 258 | -PYTHONPATH=. 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 | |
| 258 | +PYTHONPATH=. 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 | |
| 259 | 259 | ``` |
| 260 | 260 | |
| 261 | 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). |
| @@ -278,7 +278,9 @@ | ||
| 278 | 278 | |
| 279 | 279 | | | Model | AutoCodeRover cmd line argument | |
| 280 | 280 | |:--------------:|---------------|--------------| |
| 281 | -| OpenAI | gpt-4-turbo-2024-04-09 | --model gpt-4-turbo-2024-04-09 | | |
| 281 | +| OpenAI | gpt-4o-2024-08-06 | --model gpt-4o-2024-08-06 | | |
| 282 | +| | gpt-4o-2024-05-13 | --model gpt-4o-2024-05-13 | | |
| 283 | +| | gpt-4-turbo-2024-04-09 | --model gpt-4-turbo-2024-04-09 | | |
| 282 | 284 | | | gpt-4-0125-preview | --model gpt-4-0125-preview | |
| 283 | 285 | | | gpt-4-1106-preview | --model gpt-4-1106-preview | |
| 284 | 286 | | | gpt-3.5-turbo-0125 | --model gpt-3.5-turbo-0125 | |
modified app/log.py +4 −1
| @@ -10,7 +10,10 @@ | ||
| 10 | 10 | |
| 11 | 11 | |
| 12 | 12 | def terminal_width(): |
| 13 | - return get_terminal_size().columns | |
| 13 | + try: | |
| 14 | + return get_terminal_size().columns | |
| 15 | + except OSError: | |
| 16 | + return 80 | |
| 14 | 17 | |
| 15 | 18 | |
| 16 | 19 | WIDTH = min(120, terminal_width() - 10) |
modified app/main.py +12 −2
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | """ |
| 4 | 4 | |
| 5 | 5 | import json |
| 6 | +import shutil | |
| 6 | 7 | from argparse import ArgumentParser |
| 7 | 8 | from collections.abc import Callable, Mapping, Sequence |
| 8 | 9 | from concurrent.futures import ProcessPoolExecutor |
| @@ -154,7 +155,11 @@ | ||
| 154 | 155 | parser.add_argument( |
| 155 | 156 | "--clone-link", type=str, help="The link to the repository to clone." |
| 156 | 157 | ) |
| 157 | - parser.add_argument("--commit-hash", type=str, help="The commit hash to checkout.") | |
| 158 | + parser.add_argument( | |
| 159 | + "--commit-hash", | |
| 160 | + type=str, | |
| 161 | + help="The commit hash to checkout. If not specified, the latest commit on default branch will be used.", | |
| 162 | + ) | |
| 158 | 163 | parser.add_argument("--issue-link", type=str, help="The link to the issue.") |
| 159 | 164 | parser.add_argument( |
| 160 | 165 | "--setup-dir", |
| @@ -468,11 +473,16 @@ | ||
| 468 | 473 | f"Patch generation is disabled. Please find fix locations at: {task_output_dir}/fix_locations.json" |
| 469 | 474 | ) |
| 470 | 475 | else: |
| 476 | + output_patch_path = pjoin(task_output_dir, "final_patch.diff") | |
| 471 | 477 | final_patch_path = get_final_patch_path(task_output_dir) |
| 472 | 478 | if final_patch_path is not None: |
| 479 | + # cppy the final patch to the fixed path | |
| 480 | + shutil.copy2(final_patch_path, output_patch_path) | |
| 481 | + | |
| 473 | 482 | log.log_and_always_print( |
| 474 | - f"Please find the generated patch at: {final_patch_path}" | |
| 483 | + f"Please find the generated patch at: {output_patch_path}" | |
| 475 | 484 | ) |
| 485 | + | |
| 476 | 486 | if isinstance(task, RawSweTask): |
| 477 | 487 | log.log_and_always_print( |
| 478 | 488 | "[SWE-bench mode] Note that the patch may be move to other paths in SWE-bench mode. " |
modified app/model/claude.py +14 −4
| @@ -34,11 +34,13 @@ | ||
| 34 | 34 | name: str, |
| 35 | 35 | cost_per_input: float, |
| 36 | 36 | cost_per_output: float, |
| 37 | + max_output_token: int = 4096, | |
| 37 | 38 | parallel_tool_call: bool = False, |
| 38 | 39 | ): |
| 39 | 40 | if self._initialized: |
| 40 | 41 | return |
| 41 | 42 | super().__init__(name, cost_per_input, cost_per_output, parallel_tool_call) |
| 43 | + self.max_output_token = max_output_token | |
| 42 | 44 | self._initialized = True |
| 43 | 45 | |
| 44 | 46 | def setup(self) -> None: |
| @@ -72,9 +74,13 @@ | ||
| 72 | 74 | top_p=1, |
| 73 | 75 | tools=None, |
| 74 | 76 | response_format: Literal["text", "json_object"] = "text", |
| 77 | + temperature: float | None = None, | |
| 75 | 78 | **kwargs, |
| 76 | 79 | ): |
| 77 | 80 | # FIXME: ignore tools field since we don't use tools now |
| 81 | + if temperature is None: | |
| 82 | + temperature = common.MODEL_TEMP | |
| 83 | + | |
| 78 | 84 | try: |
| 79 | 85 | # antropic models - prefilling response with { increase the success rate |
| 80 | 86 | # of producing json output |
| @@ -85,8 +91,8 @@ | ||
| 85 | 91 | response = litellm.completion( |
| 86 | 92 | model=self.name, |
| 87 | 93 | messages=messages, |
| 88 | - temperature=common.MODEL_TEMP, | |
| 89 | - max_tokens=1024, | |
| 94 | + temperature=temperature, | |
| 95 | + max_tokens=self.max_output_token, | |
| 90 | 96 | top_p=top_p, |
| 91 | 97 | stream=False, |
| 92 | 98 | ) |
| @@ -122,7 +128,7 @@ | ||
| 122 | 128 | super().__init__( |
| 123 | 129 | "claude-3-opus-20240229", 0.000015, 0.000075, parallel_tool_call=True |
| 124 | 130 | ) |
| 125 | - self.note = "Most powerful model from Antropic" | |
| 131 | + self.note = "Most powerful model among Claude 3" | |
| 126 | 132 | |
| 127 | 133 | |
| 128 | 134 | class Claude3Sonnet(AnthropicModel): |
| @@ -144,6 +150,10 @@ | ||
| 144 | 150 | class Claude3_5Sonnet(AnthropicModel): |
| 145 | 151 | def __init__(self): |
| 146 | 152 | super().__init__( |
| 147 | - "claude-3-5-sonnet-20240620", 0.000003, 0.000015, parallel_tool_call=True | |
| 153 | + "claude-3-5-sonnet-20240620", | |
| 154 | + 0.000003, | |
| 155 | + 0.000015, | |
| 156 | + max_output_token=8192, | |
| 157 | + parallel_tool_call=True, | |
| 148 | 158 | ) |
| 149 | 159 | self.note = "Most intelligent model from Antropic" |
modified app/model/gpt.py +39 −14
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | import sys |
| 8 | 8 | from typing import Literal, cast |
| 9 | 9 | |
| 10 | +from loguru import logger | |
| 10 | 11 | from openai import BadRequestError, OpenAI |
| 11 | 12 | from openai.types.chat import ( |
| 12 | 13 | ChatCompletion, |
| @@ -45,6 +46,7 @@ | ||
| 45 | 46 | def __init__( |
| 46 | 47 | self, |
| 47 | 48 | name: str, |
| 49 | + max_output_token: int, | |
| 48 | 50 | cost_per_input: float, |
| 49 | 51 | cost_per_output: float, |
| 50 | 52 | parallel_tool_call: bool = False, |
| @@ -52,6 +54,10 @@ | ||
| 52 | 54 | if self._initialized: |
| 53 | 55 | return |
| 54 | 56 | super().__init__(name, cost_per_input, cost_per_output, parallel_tool_call) |
| 57 | + # max number of output tokens allowed in model response | |
| 58 | + # sometimes we want to set a lower number for models with smaller context window, | |
| 59 | + # because output token limit consumes part of the context window | |
| 60 | + self.max_output_token = max_output_token | |
| 55 | 61 | # client for making request |
| 56 | 62 | self.client: OpenAI | None = None |
| 57 | 63 | self._initialized = True |
| @@ -84,7 +90,8 @@ | ||
| 84 | 90 | return content |
| 85 | 91 | |
| 86 | 92 | def extract_resp_func_calls( |
| 87 | - self, chat_completion_message: ChatCompletionMessage | |
| 93 | + self, | |
| 94 | + chat_completion_message: ChatCompletionMessage, | |
| 88 | 95 | ) -> list[FunctionCallIntent]: |
| 89 | 96 | """ |
| 90 | 97 | Given a chat completion message, extract the function calls from it. |
| @@ -124,6 +131,7 @@ | ||
| 124 | 131 | top_p: float = 1, |
| 125 | 132 | tools: list[dict] | None = None, |
| 126 | 133 | response_format: Literal["text", "json_object"] = "text", |
| 134 | + temperature: float | None = None, | |
| 127 | 135 | **kwargs, |
| 128 | 136 | ) -> tuple[ |
| 129 | 137 | str, |
| @@ -147,6 +155,9 @@ | ||
| 147 | 155 | Raw response and parsed components. |
| 148 | 156 | The raw response is to be sent back as part of the message history. |
| 149 | 157 | """ |
| 158 | + if temperature is None: | |
| 159 | + temperature = common.MODEL_TEMP | |
| 160 | + | |
| 150 | 161 | assert self.client is not None |
| 151 | 162 | try: |
| 152 | 163 | if tools is not None and len(tools) == 1: |
| @@ -158,9 +169,9 @@ | ||
| 158 | 169 | messages=messages, # type: ignore |
| 159 | 170 | tools=tools, # type: ignore |
| 160 | 171 | tool_choice=cast(ChatCompletionToolChoiceOptionParam, tool_choice), |
| 161 | - temperature=common.MODEL_TEMP, | |
| 172 | + temperature=temperature, | |
| 162 | 173 | response_format=ResponseFormat(type=response_format), |
| 163 | - max_tokens=1024, | |
| 174 | + max_tokens=self.max_output_token, | |
| 164 | 175 | top_p=top_p, |
| 165 | 176 | stream=False, |
| 166 | 177 | ) |
| @@ -169,9 +180,9 @@ | ||
| 169 | 180 | model=self.name, |
| 170 | 181 | messages=messages, # type: ignore |
| 171 | 182 | tools=tools, # type: ignore |
| 172 | - temperature=common.MODEL_TEMP, | |
| 183 | + temperature=temperature, | |
| 173 | 184 | response_format=ResponseFormat(type=response_format), |
| 174 | - max_tokens=1024, | |
| 185 | + max_tokens=self.max_output_token, | |
| 175 | 186 | top_p=top_p, |
| 176 | 187 | stream=False, |
| 177 | 188 | ) |
| @@ -201,15 +212,24 @@ | ||
| 201 | 212 | output_tokens, |
| 202 | 213 | ) |
| 203 | 214 | except BadRequestError as e: |
| 215 | + logger.debug("BadRequestError ({}): messages={}", e.code, messages) | |
| 204 | 216 | if e.code == "context_length_exceeded": |
| 205 | 217 | log_and_print("Context length exceeded") |
| 206 | 218 | raise e |
| 207 | 219 | |
| 208 | 220 | |
| 221 | +class Gpt4o_20240806(OpenaiModel): | |
| 222 | + def __init__(self): | |
| 223 | + super().__init__( | |
| 224 | + "gpt-4o-2024-08-06", 16384, 0.0000025, 0.000010, parallel_tool_call=True | |
| 225 | + ) | |
| 226 | + self.note = "Multimodal model. Up to Apr 2023." | |
| 227 | + | |
| 228 | + | |
| 209 | 229 | class Gpt4o_20240513(OpenaiModel): |
| 210 | 230 | def __init__(self): |
| 211 | 231 | super().__init__( |
| 212 | - "gpt-4o-2024-05-13", 0.000005, 0.000015, parallel_tool_call=True | |
| 232 | + "gpt-4o-2024-05-13", 4096, 0.000005, 0.000015, parallel_tool_call=True | |
| 213 | 233 | ) |
| 214 | 234 | self.note = "Multimodal model. Up to Oct 2023." |
| 215 | 235 | |
| @@ -217,7 +237,7 @@ | ||
| 217 | 237 | class Gpt4_Turbo20240409(OpenaiModel): |
| 218 | 238 | def __init__(self): |
| 219 | 239 | super().__init__( |
| 220 | - "gpt-4-turbo-2024-04-09", 0.00001, 0.00003, parallel_tool_call=True | |
| 240 | + "gpt-4-turbo-2024-04-09", 4096, 0.00001, 0.00003, parallel_tool_call=True | |
| 221 | 241 | ) |
| 222 | 242 | self.note = "Turbo with vision. Up to Dec 2023." |
| 223 | 243 | |
| @@ -225,7 +245,7 @@ | ||
| 225 | 245 | class Gpt4_0125Preview(OpenaiModel): |
| 226 | 246 | def __init__(self): |
| 227 | 247 | super().__init__( |
| 228 | - "gpt-4-0125-preview", 0.00001, 0.00003, parallel_tool_call=True | |
| 248 | + "gpt-4-0125-preview", 4096, 0.00001, 0.00003, parallel_tool_call=True | |
| 229 | 249 | ) |
| 230 | 250 | self.note = "Turbo. Up to Dec 2023." |
| 231 | 251 | |
| @@ -233,7 +253,7 @@ | ||
| 233 | 253 | class Gpt4_1106Preview(OpenaiModel): |
| 234 | 254 | def __init__(self): |
| 235 | 255 | super().__init__( |
| 236 | - "gpt-4-1106-preview", 0.00001, 0.00003, parallel_tool_call=True | |
| 256 | + "gpt-4-1106-preview", 4096, 0.00001, 0.00003, parallel_tool_call=True | |
| 237 | 257 | ) |
| 238 | 258 | self.note = "Turbo. Up to Apr 2023." |
| 239 | 259 | |
| @@ -242,7 +262,7 @@ | ||
| 242 | 262 | # cheapest gpt model |
| 243 | 263 | def __init__(self): |
| 244 | 264 | super().__init__( |
| 245 | - "gpt-3.5-turbo-0125", 0.0000005, 0.0000015, parallel_tool_call=True | |
| 265 | + "gpt-3.5-turbo-0125", 1024, 0.0000005, 0.0000015, parallel_tool_call=True | |
| 246 | 266 | ) |
| 247 | 267 | self.note = "Turbo. Up to Sep 2021." |
| 248 | 268 | |
| @@ -250,24 +270,29 @@ | ||
| 250 | 270 | class Gpt35_Turbo1106(OpenaiModel): |
| 251 | 271 | def __init__(self): |
| 252 | 272 | super().__init__( |
| 253 | - "gpt-3.5-turbo-1106", 0.000001, 0.000002, parallel_tool_call=True | |
| 273 | + "gpt-3.5-turbo-1106", 1024, 0.000001, 0.000002, parallel_tool_call=True | |
| 254 | 274 | ) |
| 255 | 275 | self.note = "Turbo. Up to Sep 2021." |
| 256 | 276 | |
| 257 | 277 | |
| 258 | 278 | class Gpt35_Turbo16k_0613(OpenaiModel): |
| 259 | 279 | def __init__(self): |
| 260 | - super().__init__("gpt-3.5-turbo-16k-0613", 0.000003, 0.000004) | |
| 280 | + super().__init__("gpt-3.5-turbo-16k-0613", 1024, 0.000003, 0.000004) | |
| 261 | 281 | self.note = "Turbo. Deprecated. Up to Sep 2021." |
| 262 | 282 | |
| 263 | 283 | |
| 264 | 284 | class Gpt35_Turbo0613(OpenaiModel): |
| 265 | 285 | def __init__(self): |
| 266 | - super().__init__("gpt-3.5-turbo-0613", 0.0000015, 0.000002) | |
| 286 | + super().__init__("gpt-3.5-turbo-0613", 512, 0.0000015, 0.000002) | |
| 267 | 287 | self.note = "Turbo. Deprecated. Only 4k window. Up to Sep 2021." |
| 268 | 288 | |
| 269 | 289 | |
| 270 | 290 | class Gpt4_0613(OpenaiModel): |
| 271 | 291 | def __init__(self): |
| 272 | - super().__init__("gpt-4-0613", 0.00003, 0.00006) | |
| 292 | + super().__init__("gpt-4-0613", 512, 0.00003, 0.00006) | |
| 273 | 293 | self.note = "Not turbo. Up to Sep 2021." |
| 294 | + | |
| 295 | + | |
| 296 | +class Gpt4o_mini_20240718(OpenaiModel): | |
| 297 | + def __init__(self): | |
| 298 | + super().__init__("gpt-4o-mini-2024-07-18", 4096, 0.00000015, 0.0000006) |
modified app/model/register.py +1 −0
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | Register all models. This is called in main. |
| 7 | 7 | """ |
| 8 | 8 | common.register_model(gpt.Gpt4o_20240513()) |
| 9 | + common.register_model(gpt.Gpt4o_mini_20240718()) | |
| 9 | 10 | common.register_model(gpt.Gpt4_Turbo20240409()) |
| 10 | 11 | common.register_model(gpt.Gpt4_0125Preview()) |
| 11 | 12 | common.register_model(gpt.Gpt4_1106Preview()) |
modified app/raw_tasks.py +6 −1
| @@ -92,12 +92,13 @@ | ||
| 92 | 92 | self, |
| 93 | 93 | task_id: str, |
| 94 | 94 | clone_link: str, |
| 95 | - commit_hash: str, | |
| 95 | + commit_hash: str | None, | |
| 96 | 96 | issue_link: str, |
| 97 | 97 | setup_dir: str, |
| 98 | 98 | ): |
| 99 | 99 | self._task_id = task_id |
| 100 | 100 | self.clone_link = clone_link |
| 101 | + # if commit_hash is None, assume using the HEAD of default branch | |
| 101 | 102 | self.commit_hash = commit_hash |
| 102 | 103 | self.issue_link = issue_link |
| 103 | 104 | self.setup_dir = setup_dir |
| @@ -118,6 +119,10 @@ | ||
| 118 | 119 | shutil.rmtree(clone_path) |
| 119 | 120 | app_utils.clone_repo(self.clone_link, str(clone_path.parent), clone_path.name) |
| 120 | 121 | log_and_print(f"Cloned source code to {clone_path}.") |
| 122 | + if self.commit_hash is None: | |
| 123 | + # let's get the current commit hash | |
| 124 | + with app_utils.cd(clone_path): | |
| 125 | + self.commit_hash = app_utils.get_current_commit_hash() | |
| 121 | 126 | |
| 122 | 127 | def dump_meta_data(self, output_dir: str): |
| 123 | 128 | meta = { |