@@ -84,6 +84,7 @@ class LLMFL(FL):
8484{file_content}
8585```
8686"""
87+
8788 obtain_relevant_code_combine_top_n_prompt = """
8889Please review the following GitHub problem description and relevant files, and provide a set of locations that need to be edited to fix the issue.
8990The locations can be specified as class names, function or method names, or exact line numbers that require modification.
@@ -97,6 +98,8 @@ class LLMFL(FL):
9798###
9899
99100Please provide the class name, function or method name, or the exact line numbers that need to be edited.
101+ The possible location outputs should be either "class", "function" or "line".
102+
100103### Examples:
101104```
102105full_path1/file1.py
@@ -114,7 +117,7 @@ class LLMFL(FL):
114117line: 156
115118```
116119
117- Return just the location(s)
120+ Return just the location(s) wrapped with ```.
118121"""
119122
120123 obtain_relevant_code_combine_top_n_no_line_number_prompt = """
@@ -144,7 +147,7 @@ class LLMFL(FL):
144147function: my_function2
145148```
146149
147- Return just the location(s)
150+ Return just the location(s) wrapped with ```.
148151"""
149152 obtain_relevant_functions_and_vars_from_compressed_files_prompt_more = """
150153Please look through the following GitHub Problem Description and the Skeleton of Relevant Files.
@@ -180,7 +183,7 @@ class LLMFL(FL):
180183class: MyClass5
181184```
182185
183- Return just the locations.
186+ Return just the locations wrapped with ``` .
184187"""
185188
186189 obtain_relevant_functions_and_vars_from_raw_files_prompt = """
@@ -217,7 +220,7 @@ class LLMFL(FL):
217220class: MyClass5
218221```
219222
220- Return just the locations.
223+ Return just the locations wrapped with ``` .
221224"""
222225
223226 def __init__ (
@@ -577,7 +580,35 @@ def localize_line_from_coarse_function_locs(
577580 )
578581 self .logger .info (f"prompting with message:\n { message } " )
579582 self .logger .info ("=" * 80 )
580- assert num_tokens_from_messages (message , self .model_name ) < MAX_CONTEXT_LENGTH
583+
584+ def message_too_long (message ):
585+ return (
586+ num_tokens_from_messages (message , self .model_name ) >= MAX_CONTEXT_LENGTH
587+ )
588+
589+ while message_too_long (message ) and len (coarse_locs ) > 1 :
590+ self .logger .info (f"reducing to \n { len (coarse_locs )} files" )
591+ coarse_locs .popitem ()
592+ topn_content , file_loc_intervals = construct_topn_file_context (
593+ coarse_locs ,
594+ file_names ,
595+ file_contents ,
596+ self .structure ,
597+ context_window = context_window ,
598+ loc_interval = True ,
599+ add_space = add_space ,
600+ sticky_scroll = sticky_scroll ,
601+ no_line_number = no_line_number ,
602+ )
603+ message = template .format (
604+ problem_statement = self .problem_statement , file_contents = topn_content
605+ )
606+
607+ if message_too_long (message ):
608+ raise ValueError (
609+ "The remaining file content is too long to fit within the context length"
610+ )
611+
581612 if mock :
582613 self .logger .info ("Skipping querying model since mock=True" )
583614 traj = {
@@ -596,7 +627,9 @@ def localize_line_from_coarse_function_locs(
596627 temperature = temperature ,
597628 batch_size = num_samples ,
598629 )
599- raw_trajs = model .codegen (message , num_samples = num_samples )
630+ raw_trajs = model .codegen (
631+ message , num_samples = num_samples , prompt_cache = num_samples > 1
632+ )
600633
601634 # Merge trajectories
602635 raw_outputs = [raw_traj ["response" ] for raw_traj in raw_trajs ]
0 commit comments