@@ -105,7 +105,7 @@ def gemini_qna(
105
105
logging .info (f"Student files: { student_files } " )
106
106
logging .info (f"Readme file: { readme_file } " )
107
107
108
- consolidated_question = get_the_question (
108
+ consolidated_question = get_prompt (
109
109
report_paths ,
110
110
student_files ,
111
111
readme_file ,
@@ -117,22 +117,13 @@ def gemini_qna(
117
117
return answers
118
118
119
119
120
- def get_the_question (
120
+ def get_prompt (
121
121
report_paths :Tuple [pathlib .Path ],
122
122
student_files :Tuple [pathlib .Path ],
123
123
readme_file :pathlib .Path ,
124
124
explanation_in :str ,
125
125
) -> 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 )
136
127
137
128
def get_initial_instruction (questions :List [str ],language :str ) -> str :
138
129
# 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:
146
137
return initial_instruction
147
138
148
139
149
- questions = (
140
+ prompt_list = (
150
141
# 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
153
147
# 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
+ ]
155
151
)
156
152
157
153
# 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 ))
159
174
160
- return consolidated_question
175
+ return questions
161
176
162
177
163
178
@functools .lru_cache
@@ -190,13 +205,6 @@ def collect_longrepr(data:Dict[str, str]) -> List[str]:
190
205
return longrepr_list
191
206
192
207
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
-
200
208
@functools .lru_cache
201
209
def get_report_header (explanation_in :str ) -> str :
202
210
d = {
@@ -239,42 +247,7 @@ def get_report_footer(explanation_in:str) -> str:
239
247
)
240
248
241
249
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 :
278
251
279
252
d_instruction_start = {
280
253
'Korean' : "과제 지침 시작" ,
@@ -307,15 +280,51 @@ def get_code_instruction(
307
280
}
308
281
309
282
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 "
313
283
f"## { d_instruction_start [explanation_in ]} \n "
314
284
f"{ assignment_instruction (readme_file )} \n "
315
285
f"## { d_instruction_end [explanation_in ]} \n "
316
286
)
317
287
318
288
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
+
319
328
@functools .lru_cache
320
329
def assignment_code (student_files :Tuple [pathlib .Path ]) -> str :
321
330
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