Elffuss BraidHub

kikocis/auto-code-rover public

Increase max output tokens for gpt-4o and sonnet-3.5
Changeseta6e372ee0e4aa6ad9c9211deff241725852d75b38c89ee26e976355fffc119b4
AuthorZhang Yuntong <ang.unong@gmail.com> · 2024-08-09 11:52 +08:00
CommitterZhang Yuntong <ang.unong@gmail.com> · 2024-08-09 11:52 +08:00
Parents0cb0fe7a2cd9

Browse the files at this changeset

8 files changed

modified Dockerfile.minimal +2 −0
@@ -9,5 +9,7 @@
99
1010 COPY . /opt/auto-code-rover
1111
12+ENV PYTHONPATH=/opt/auto-code-rover
13+
1214 WORKDIR /opt/auto-code-rover
1315 RUN conda env create -f environment.yml
modified README.md +8 −6
@@ -155,12 +155,12 @@
155155 ```
156156 cd /opt/auto-code-rover
157157 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>
159159 ```
160160 Here is an example command for running ACR on an issue from the langchain GitHub issue tracker:
161161
162162 ```
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
164164 ```
165165
166166 The `<task id>` can be any string used to identify this issue.
@@ -189,7 +189,7 @@
189189 ```
190190 cd /opt/auto-code-rover
191191 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>
193193 ```
194194
195195 If patch generation is successful, the path to the generated patch will be printed in the end.
@@ -243,7 +243,7 @@
243243 ```
244244 cd /opt/auto-code-rover
245245 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
247247 ```
248248
249249 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 @@
255255 ```
256256 cd /opt/auto-code-rover
257257 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
259259 ```
260260
261261 **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 @@
278278
279279 | | Model | AutoCodeRover cmd line argument |
280280 |:--------------:|---------------|--------------|
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 |
282284 | | gpt-4-0125-preview | --model gpt-4-0125-preview |
283285 | | gpt-4-1106-preview | --model gpt-4-1106-preview |
284286 | | gpt-3.5-turbo-0125 | --model gpt-3.5-turbo-0125 |
modified app/log.py +4 −1
@@ -10,7 +10,10 @@
1010
1111
1212 def terminal_width():
13- return get_terminal_size().columns
13+ try:
14+ return get_terminal_size().columns
15+ except OSError:
16+ return 80
1417
1518
1619 WIDTH = min(120, terminal_width() - 10)
modified app/main.py +12 −2
@@ -3,6 +3,7 @@
33 """
44
55 import json
6+import shutil
67 from argparse import ArgumentParser
78 from collections.abc import Callable, Mapping, Sequence
89 from concurrent.futures import ProcessPoolExecutor
@@ -154,7 +155,11 @@
154155 parser.add_argument(
155156 "--clone-link", type=str, help="The link to the repository to clone."
156157 )
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+ )
158163 parser.add_argument("--issue-link", type=str, help="The link to the issue.")
159164 parser.add_argument(
160165 "--setup-dir",
@@ -468,11 +473,16 @@
468473 f"Patch generation is disabled. Please find fix locations at: {task_output_dir}/fix_locations.json"
469474 )
470475 else:
476+ output_patch_path = pjoin(task_output_dir, "final_patch.diff")
471477 final_patch_path = get_final_patch_path(task_output_dir)
472478 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+
473482 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}"
475484 )
485+
476486 if isinstance(task, RawSweTask):
477487 log.log_and_always_print(
478488 "[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 @@
3434 name: str,
3535 cost_per_input: float,
3636 cost_per_output: float,
37+ max_output_token: int = 4096,
3738 parallel_tool_call: bool = False,
3839 ):
3940 if self._initialized:
4041 return
4142 super().__init__(name, cost_per_input, cost_per_output, parallel_tool_call)
43+ self.max_output_token = max_output_token
4244 self._initialized = True
4345
4446 def setup(self) -> None:
@@ -72,9 +74,13 @@
7274 top_p=1,
7375 tools=None,
7476 response_format: Literal["text", "json_object"] = "text",
77+ temperature: float | None = None,
7578 **kwargs,
7679 ):
7780 # FIXME: ignore tools field since we don't use tools now
81+ if temperature is None:
82+ temperature = common.MODEL_TEMP
83+
7884 try:
7985 # antropic models - prefilling response with { increase the success rate
8086 # of producing json output
@@ -85,8 +91,8 @@
8591 response = litellm.completion(
8692 model=self.name,
8793 messages=messages,
88- temperature=common.MODEL_TEMP,
89- max_tokens=1024,
94+ temperature=temperature,
95+ max_tokens=self.max_output_token,
9096 top_p=top_p,
9197 stream=False,
9298 )
@@ -122,7 +128,7 @@
122128 super().__init__(
123129 "claude-3-opus-20240229", 0.000015, 0.000075, parallel_tool_call=True
124130 )
125- self.note = "Most powerful model from Antropic"
131+ self.note = "Most powerful model among Claude 3"
126132
127133
128134 class Claude3Sonnet(AnthropicModel):
@@ -144,6 +150,10 @@
144150 class Claude3_5Sonnet(AnthropicModel):
145151 def __init__(self):
146152 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,
148158 )
149159 self.note = "Most intelligent model from Antropic"
modified app/model/gpt.py +39 −14
@@ -7,6 +7,7 @@
77 import sys
88 from typing import Literal, cast
99
10+from loguru import logger
1011 from openai import BadRequestError, OpenAI
1112 from openai.types.chat import (
1213 ChatCompletion,
@@ -45,6 +46,7 @@
4546 def __init__(
4647 self,
4748 name: str,
49+ max_output_token: int,
4850 cost_per_input: float,
4951 cost_per_output: float,
5052 parallel_tool_call: bool = False,
@@ -52,6 +54,10 @@
5254 if self._initialized:
5355 return
5456 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
5561 # client for making request
5662 self.client: OpenAI | None = None
5763 self._initialized = True
@@ -84,7 +90,8 @@
8490 return content
8591
8692 def extract_resp_func_calls(
87- self, chat_completion_message: ChatCompletionMessage
93+ self,
94+ chat_completion_message: ChatCompletionMessage,
8895 ) -> list[FunctionCallIntent]:
8996 """
9097 Given a chat completion message, extract the function calls from it.
@@ -124,6 +131,7 @@
124131 top_p: float = 1,
125132 tools: list[dict] | None = None,
126133 response_format: Literal["text", "json_object"] = "text",
134+ temperature: float | None = None,
127135 **kwargs,
128136 ) -> tuple[
129137 str,
@@ -147,6 +155,9 @@
147155 Raw response and parsed components.
148156 The raw response is to be sent back as part of the message history.
149157 """
158+ if temperature is None:
159+ temperature = common.MODEL_TEMP
160+
150161 assert self.client is not None
151162 try:
152163 if tools is not None and len(tools) == 1:
@@ -158,9 +169,9 @@
158169 messages=messages, # type: ignore
159170 tools=tools, # type: ignore
160171 tool_choice=cast(ChatCompletionToolChoiceOptionParam, tool_choice),
161- temperature=common.MODEL_TEMP,
172+ temperature=temperature,
162173 response_format=ResponseFormat(type=response_format),
163- max_tokens=1024,
174+ max_tokens=self.max_output_token,
164175 top_p=top_p,
165176 stream=False,
166177 )
@@ -169,9 +180,9 @@
169180 model=self.name,
170181 messages=messages, # type: ignore
171182 tools=tools, # type: ignore
172- temperature=common.MODEL_TEMP,
183+ temperature=temperature,
173184 response_format=ResponseFormat(type=response_format),
174- max_tokens=1024,
185+ max_tokens=self.max_output_token,
175186 top_p=top_p,
176187 stream=False,
177188 )
@@ -201,15 +212,24 @@
201212 output_tokens,
202213 )
203214 except BadRequestError as e:
215+ logger.debug("BadRequestError ({}): messages={}", e.code, messages)
204216 if e.code == "context_length_exceeded":
205217 log_and_print("Context length exceeded")
206218 raise e
207219
208220
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+
209229 class Gpt4o_20240513(OpenaiModel):
210230 def __init__(self):
211231 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
213233 )
214234 self.note = "Multimodal model. Up to Oct 2023."
215235
@@ -217,7 +237,7 @@
217237 class Gpt4_Turbo20240409(OpenaiModel):
218238 def __init__(self):
219239 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
221241 )
222242 self.note = "Turbo with vision. Up to Dec 2023."
223243
@@ -225,7 +245,7 @@
225245 class Gpt4_0125Preview(OpenaiModel):
226246 def __init__(self):
227247 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
229249 )
230250 self.note = "Turbo. Up to Dec 2023."
231251
@@ -233,7 +253,7 @@
233253 class Gpt4_1106Preview(OpenaiModel):
234254 def __init__(self):
235255 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
237257 )
238258 self.note = "Turbo. Up to Apr 2023."
239259
@@ -242,7 +262,7 @@
242262 # cheapest gpt model
243263 def __init__(self):
244264 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
246266 )
247267 self.note = "Turbo. Up to Sep 2021."
248268
@@ -250,24 +270,29 @@
250270 class Gpt35_Turbo1106(OpenaiModel):
251271 def __init__(self):
252272 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
254274 )
255275 self.note = "Turbo. Up to Sep 2021."
256276
257277
258278 class Gpt35_Turbo16k_0613(OpenaiModel):
259279 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)
261281 self.note = "Turbo. Deprecated. Up to Sep 2021."
262282
263283
264284 class Gpt35_Turbo0613(OpenaiModel):
265285 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)
267287 self.note = "Turbo. Deprecated. Only 4k window. Up to Sep 2021."
268288
269289
270290 class Gpt4_0613(OpenaiModel):
271291 def __init__(self):
272- super().__init__("gpt-4-0613", 0.00003, 0.00006)
292+ super().__init__("gpt-4-0613", 512, 0.00003, 0.00006)
273293 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 @@
66 Register all models. This is called in main.
77 """
88 common.register_model(gpt.Gpt4o_20240513())
9+ common.register_model(gpt.Gpt4o_mini_20240718())
910 common.register_model(gpt.Gpt4_Turbo20240409())
1011 common.register_model(gpt.Gpt4_0125Preview())
1112 common.register_model(gpt.Gpt4_1106Preview())
modified app/raw_tasks.py +6 −1
@@ -92,12 +92,13 @@
9292 self,
9393 task_id: str,
9494 clone_link: str,
95- commit_hash: str,
95+ commit_hash: str | None,
9696 issue_link: str,
9797 setup_dir: str,
9898 ):
9999 self._task_id = task_id
100100 self.clone_link = clone_link
101+ # if commit_hash is None, assume using the HEAD of default branch
101102 self.commit_hash = commit_hash
102103 self.issue_link = issue_link
103104 self.setup_dir = setup_dir
@@ -118,6 +119,10 @@
118119 shutil.rmtree(clone_path)
119120 app_utils.clone_repo(self.clone_link, str(clone_path.parent), clone_path.name)
120121 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()
121126
122127 def dump_meta_data(self, output_dir: str):
123128 meta = {