@@ -105,7 +105,7 @@ def gemini_qna(
105105 logging .info (f"Student files: { student_files } " )
106106 logging .info (f"Readme file: { readme_file } " )
107107
108- consolidated_question = get_the_question (
108+ consolidated_question = get_prompt (
109109 report_paths ,
110110 student_files ,
111111 readme_file ,
@@ -117,22 +117,13 @@ def gemini_qna(
117117 return answers
118118
119119
120- def get_the_question (
120+ def get_prompt (
121121 report_paths :Tuple [pathlib .Path ],
122122 student_files :Tuple [pathlib .Path ],
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 , explanation_in )
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,42 @@ 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+ [
143+ get_initial_instruction (pytest_longrepr_list , explanation_in ),
144+ get_instruction_block (readme_file , explanation_in ,),
145+ ]
146+ + pytest_longrepr_list
153147 # Add the code and instructions
154- + [get_report_footer (explanation_in ), get_code_instruction (student_files , readme_file , explanation_in )]
148+ + [
149+ get_student_code_block (student_files , explanation_in ,),
150+ ]
155151 )
156152
157153 # Join all questions into a single string
158- consolidated_question = "\n \n " .join (questions )
154+ prompt_str = "\n \n " .join (prompt_list )
155+
156+ return prompt_str
157+
158+
159+ def collect_longrepr_from_multiple_reports (pytest_json_report_paths :Tuple [pathlib .Path ], explanation_in :str ) -> List [str ]:
160+ questions = []
161+
162+ # Process each report file
163+ for pytest_json_report_path in pytest_json_report_paths :
164+ logging .info (f"Processing report file: { pytest_json_report_path } " )
165+ data = json .loads (pytest_json_report_path .read_text ())
166+
167+ longrepr_list = collect_longrepr (data )
168+
169+ questions += longrepr_list
170+
171+ if questions :
172+ questions .insert (0 , get_report_header (explanation_in ))
173+ questions .append (get_report_footer (explanation_in ))
159174
160- return consolidated_question
175+ return questions
161176
162177
163178@functools .lru_cache
@@ -190,13 +205,6 @@ def collect_longrepr(data:Dict[str, str]) -> List[str]:
190205 return longrepr_list
191206
192207
193- @functools .lru_cache
194- def get_question (longrepr :str , explanation_in :str ,) -> str :
195- return (
196- get_report_header (explanation_in ) + f"{ longrepr } \n " + get_report_footer (explanation_in )
197- )
198-
199-
200208@functools .lru_cache
201209def get_report_header (explanation_in :str ) -> str :
202210 d = {
@@ -239,42 +247,7 @@ def get_report_footer(explanation_in:str) -> str:
239247 )
240248
241249
242- @functools .lru_cache
243- def get_code_instruction (
244- student_files :Tuple [pathlib .Path ],
245- readme_file :pathlib .Path ,
246- explanation_in :str ,
247- ) -> str :
248-
249- d_homework_start = {
250- 'Korean' : "숙제 제출 코드 시작" ,
251- 'English' : "Homework Submission Code Start" ,
252- 'Bahasa Indonesia' : "Kode Pengumpulan Tugas Dimulai" ,
253- 'Chinese' : "作业提交代码开始" ,
254- 'French' : '''Début du code de soumission des devoirs''' ,
255- 'German' : "Code für die Einreichung von Hausaufgaben von hier aus" ,
256- 'Italian' : "Inizio del codice di invio dei compiti" ,
257- 'Japanese' : "宿題提出コード開始" ,
258- 'Nederlands' : "Huiswerk inzendcode begint" ,
259- 'Spanish' : "Inicio del código de envío de tareas" ,
260- 'Thai' : "การส่งงานเริ่มต้น" ,
261- 'Vietnamese' : "Bắt đầu mã nộp bài tập" ,
262- }
263-
264- d_homework_end = {
265- 'Korean' : "숙제 제출 코드 끝" ,
266- 'English' : "Homework Submission Code End" ,
267- 'Bahasa Indonesia' : "Kode Pengumpulan Tugas Berakhir" ,
268- 'Chinese' : "作业提交代码结束" ,
269- 'French' : '''Fin du code de soumission des devoirs''' ,
270- 'German' : "Ende der Hausaufgaben-Einreichungscodes" ,
271- 'Italian' : "Fine del codice di invio dei compiti" ,
272- 'Japanese' : "宿題提出コード終わり" ,
273- 'Nederlands' : "Huiswerk inzendcode eindigt" ,
274- 'Spanish' : "Fin del código de envío de tareas" ,
275- 'Thai' : "การส่งงานสิ้นสุด" ,
276- 'Vietnamese' : "Mã nộp bài tập kết thúc" ,
277- }
250+ def get_instruction_block (readme_file :pathlib .Path , explanation_in :str = 'Korean' ,) -> str :
278251
279252 d_instruction_start = {
280253 'Korean' : "과제 지침 시작" ,
@@ -307,15 +280,51 @@ def get_code_instruction(
307280 }
308281
309282 return (
310- f"\n \n ## { d_homework_start [explanation_in ]} \n "
311- f"{ assignment_code (student_files )} \n "
312- f"## { d_homework_end [explanation_in ]} \n "
313283 f"## { d_instruction_start [explanation_in ]} \n "
314284 f"{ assignment_instruction (readme_file )} \n "
315285 f"## { d_instruction_end [explanation_in ]} \n "
316286 )
317287
318288
289+ def get_student_code_block (student_files :Tuple [pathlib .Path ], explanation_in :str ) -> str :
290+
291+ d_homework_start = {
292+ 'Korean' : "숙제 제출 코드 시작" ,
293+ 'English' : "Homework Submission Code Start" ,
294+ 'Bahasa Indonesia' : "Kode Pengumpulan Tugas Dimulai" ,
295+ 'Chinese' : "作业提交代码开始" ,
296+ 'French' : '''Début du code de soumission des devoirs''' ,
297+ 'German' : "Code für die Einreichung von Hausaufgaben von hier aus" ,
298+ 'Italian' : "Inizio del codice di invio dei compiti" ,
299+ 'Japanese' : "宿題提出コード開始" ,
300+ 'Nederlands' : "Huiswerk inzendcode begint" ,
301+ 'Spanish' : "Inicio del código de envío de tareas" ,
302+ 'Thai' : "เริ่มส่งรหัสการบ้าน" ,
303+ 'Vietnamese' : "Bắt đầu mã nộp bài tập" ,
304+ }
305+
306+ d_homework_end = {
307+ 'Korean' : "숙제 제출 코드 끝" ,
308+ 'English' : "Homework Submission Code End" ,
309+ 'Bahasa Indonesia' : "Kode Pengumpulan Tugas Berakhir" ,
310+ 'Chinese' : "作业提交代码结束" ,
311+ 'French' : '''Fin du code de soumission des devoirs''' ,
312+ 'German' : "Ende der Hausaufgaben-Einreichungscodes" ,
313+ 'Italian' : "Fine del codice di invio dei compiti" ,
314+ 'Japanese' : "宿題提出コード終わり" ,
315+ 'Nederlands' : "Huiswerk inzendcode eindigt" ,
316+ 'Spanish' : "Fin del código de envío de tareas" ,
317+ 'Thai' : "จบรหัสส่งการบ้าน" ,
318+ 'Vietnamese' : "Mã nộp bài tập kết thúc" ,
319+ }
320+
321+ return (
322+ f"\n \n ## { d_homework_start [explanation_in ]} \n "
323+ f"{ assignment_code (student_files )} \n "
324+ f"## { d_homework_end [explanation_in ]} \n "
325+ )
326+
327+
319328@functools .lru_cache
320329def assignment_code (student_files :Tuple [pathlib .Path ]) -> str :
321330 return '\n \n ' .join ([f"# begin : { str (f .name )} ======\n { f .read_text ()} \n # end : { str (f .name )} ======\n " for f in student_files ])
0 commit comments