Skip to content

Commit caed139

Browse files
authored
Merge pull request #7 from YanxinLu/main
add background prompt template
2 parents 24760e7 + bbfc8c3 commit caed139

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

eval/data/multistep_template.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
PROBLEM DESCRIPTION:
2+
You will be provided with problem steps along with background knowledge necessary for solving the problem. Your task will be to develop a Python solution focused on the next step of the problem-solving process.
3+
4+
PROBLEM STEPS AND FUNCTION CODE:
5+
Here, you'll find the Python code for the initial steps of the problem-solving process. This code is integral to building the solution.
6+
7+
{problem_steps_str}
8+
9+
NEXT STEP - PROBLEM STEP AND FUNCTION HEADER:
10+
This part will describe the next step in the problem-solving process. A function header will be provided, and your task is to develop the Python code for this next step based on the provided description and function header.
11+
12+
{next_step_str}
13+
14+
DEPENDENCIES:
15+
Use only the following dependencies in your solution. Do not include these dependencies at the beginning of your code.
16+
17+
{dependencies}
18+
19+
RESPONSE GUIDELINES:
20+
Now, based on the instructions and information provided above, write the complete and executable Python program for the next step in a single block.
21+
Your response should focus exclusively on implementing the solution for the next step, adhering closely to the specified function header and the context provided by the initial steps.
22+
Your response should NOT include the dependencies and functions of all previous steps. If your next step function calls functions from previous steps, please make sure it uses the headers provided without modification.
23+
DO NOT generate EXAMPLE USAGE OR TEST CODE in your response. Please make sure your response python code in format of ```python```.

eval/scripts/gencode_json.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
DEFAULT_PROMPT_TEMPLATE = Path("eval", "data", "background_comment_template.txt").read_text()
13-
13+
BACKGOUND_PROMPT_TEMPLATE = Path("eval", "data", "multistep_template.txt").read_text()
1414

1515
class Gencode:
1616
def __init__(self, model: str, output_dir: Path,
@@ -132,7 +132,6 @@ def process_problem_steps(self, problem_data: dict, num_steps: int):
132132
def generate_prompt_with_steps(self, prob_data: dict, num_steps: int,
133133
prompt_template=DEFAULT_PROMPT_TEMPLATE):
134134
# parse the input file and extract the content
135-
136135
problem_steps_str, next_step_str, previous_code_str = self.process_problem_steps(prob_data,
137136
num_steps)
138137
dependencies = prob_data["required_dependencies"]
@@ -194,6 +193,7 @@ def main(model: str,
194193
model=model, output_dir=output_dir,
195194
prompt_dir=prompt_dir, with_background=with_background, temperature=temperature
196195
)
196+
prompt_template = BACKGOUND_PROMPT_TEMPLATE if with_background else DEFAULT_PROMPT_TEMPLATE
197197
data = read_from_jsonl(input_path)
198198
for problem in data:
199199
prob_id = problem['problem_id']
@@ -203,7 +203,7 @@ def main(model: str,
203203
if (prob_id == "13" and i == 5) or (prob_id == "62" and i == 0)\
204204
or (prob_id == "76" and i == 2):
205205
continue
206-
gcode.generate_response_with_steps(problem, i + 1, steps, model)
206+
gcode.generate_response_with_steps(problem, i + 1, steps, model, prompt_template)
207207

208208

209209
if __name__ == "__main__":

0 commit comments

Comments
 (0)