Skip to content

Commit d8fe918

Browse files
committed
refactor collect_longrepr_from_multiple_reports()
for more flexibility and reusability
1 parent c13c2fd commit d8fe918

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

ai_tutor.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,7 @@ def get_prompt(
123123
readme_file:pathlib.Path,
124124
explanation_in:str,
125125
) -> str:
126-
questions = []
127-
128-
# Process each report file
129-
for report_path in report_paths:
130-
logging.info(f"Processing report file: {report_path}")
131-
data = json.loads(report_path.read_text())
132-
133-
longrepr_list = collect_longrepr(data)
134-
135-
questions += longrepr_list
126+
pytest_longrepr_list = collect_longrepr_from_multiple_reports(report_paths)
136127

137128
def get_initial_instruction(questions:List[str],language:str) -> str:
138129
# Add the main directive or instruction based on whether there are failed tests
@@ -146,18 +137,33 @@ def get_initial_instruction(questions:List[str],language:str) -> str:
146137
return initial_instruction
147138

148139

149-
questions = (
140+
prompt_list = (
150141
# Add the initial instruction
151-
[get_initial_instruction(questions, explanation_in), get_report_header(explanation_in)]
152-
+ questions
142+
[get_initial_instruction(pytest_longrepr_list, explanation_in), get_report_header(explanation_in)]
143+
+ pytest_longrepr_list
153144
# Add the code and instructions
154145
+ [get_report_footer(explanation_in), get_code_instruction(student_files, readme_file, explanation_in)]
155146
)
156147

157148
# Join all questions into a single string
158-
consolidated_question = "\n\n".join(questions)
149+
prompt_str = "\n\n".join(prompt_list)
150+
151+
return prompt_str
152+
153+
154+
def collect_longrepr_from_multiple_reports(pytest_json_report_paths:Tuple[pathlib.Path]) -> List[str]:
155+
questions = []
156+
157+
# Process each report file
158+
for pytest_json_report_path in pytest_json_report_paths:
159+
logging.info(f"Processing report file: {pytest_json_report_path}")
160+
data = json.loads(pytest_json_report_path.read_text())
161+
162+
longrepr_list = collect_longrepr(data)
163+
164+
questions += longrepr_list
159165

160-
return consolidated_question
166+
return questions
161167

162168

163169
@functools.lru_cache

0 commit comments

Comments
 (0)