Skip to content

Commit 9570ae9

Browse files
committed
move report header & footer into collect_longrepr_from_multiple_reports()
more modular
1 parent 194c466 commit 9570ae9

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

ai_tutor.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def get_prompt(
123123
readme_file:pathlib.Path,
124124
explanation_in:str,
125125
) -> str:
126-
pytest_longrepr_list = collect_longrepr_from_multiple_reports(report_paths)
126+
pytest_longrepr_list = collect_longrepr_from_multiple_reports(report_paths, explanation_in)
127127

128128
def get_initial_instruction(questions:List[str],language:str) -> str:
129129
# Add the main directive or instruction based on whether there are failed tests
@@ -139,11 +139,10 @@ def get_initial_instruction(questions:List[str],language:str) -> str:
139139

140140
prompt_list = (
141141
# Add the initial instruction
142-
[get_initial_instruction(pytest_longrepr_list, explanation_in), get_report_header(explanation_in)]
142+
[get_initial_instruction(pytest_longrepr_list, explanation_in),]
143143
+ pytest_longrepr_list
144144
# Add the code and instructions
145145
+ [
146-
get_report_footer(explanation_in),
147146
get_student_code_block(student_files, explanation_in,),
148147
get_instruction_block(readme_file, explanation_in,)
149148
]
@@ -155,7 +154,7 @@ def get_initial_instruction(questions:List[str],language:str) -> str:
155154
return prompt_str
156155

157156

158-
def collect_longrepr_from_multiple_reports(pytest_json_report_paths:Tuple[pathlib.Path]) -> List[str]:
157+
def collect_longrepr_from_multiple_reports(pytest_json_report_paths:Tuple[pathlib.Path], explanation_in:str) -> List[str]:
159158
questions = []
160159

161160
# Process each report file
@@ -167,6 +166,10 @@ def collect_longrepr_from_multiple_reports(pytest_json_report_paths:Tuple[pathli
167166

168167
questions += longrepr_list
169168

169+
if questions:
170+
questions.insert(0, get_report_header(explanation_in))
171+
questions.append(get_report_footer(explanation_in))
172+
170173
return questions
171174

172175

tests/test_ai_tutor.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,17 @@ def test_collect_longrepr_div_zero_dict__returns_non_empty(json_dict_div_zero_tr
5858

5959

6060
def test_collect_longrepr_from_multiple_reports__returns_non_empty(
61-
sample_report_path,
62-
div_zero_report_path,
61+
sample_report_path:pathlib.Path,
62+
div_zero_report_path:pathlib.Path,
63+
explanation_in:str
6364
):
6465
multiple_reports = (
6566
sample_report_path,
6667
div_zero_report_path
6768
)
6869
result = ai_tutor.collect_longrepr_from_multiple_reports(
69-
multiple_reports
70+
multiple_reports,
71+
explanation_in=explanation_in,
7072
)
7173

7274
assert result

0 commit comments

Comments
 (0)