Skip to content

Commit 793cd28

Browse files
committed
refactor instruction & student code blocks
1 parent 961def7 commit 793cd28

2 files changed

Lines changed: 63 additions & 49 deletions

File tree

ai_tutor.py

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ def get_initial_instruction(questions:List[str],language:str) -> str:
142142
[get_initial_instruction(pytest_longrepr_list, explanation_in), get_report_header(explanation_in)]
143143
+ pytest_longrepr_list
144144
# Add the code and instructions
145-
+ [get_report_footer(explanation_in), get_code_instruction(student_files, readme_file, explanation_in)]
145+
+ [
146+
get_report_footer(explanation_in),
147+
get_student_code_block(student_files, explanation_in,),
148+
get_instruction_block(readme_file, explanation_in,)
149+
]
146150
)
147151

148152
# Join all questions into a single string
@@ -245,42 +249,7 @@ def get_report_footer(explanation_in:str) -> str:
245249
)
246250

247251

248-
@functools.lru_cache
249-
def get_code_instruction(
250-
student_files:Tuple[pathlib.Path],
251-
readme_file:pathlib.Path,
252-
explanation_in:str,
253-
) -> str:
254-
255-
d_homework_start = {
256-
'Korean': "숙제 제출 코드 시작",
257-
'English': "Homework Submission Code Start",
258-
'Bahasa Indonesia': "Kode Pengumpulan Tugas Dimulai",
259-
'Chinese': "作业提交代码开始",
260-
'French': '''Début du code de soumission des devoirs''',
261-
'German': "Code für die Einreichung von Hausaufgaben von hier aus",
262-
'Italian': "Inizio del codice di invio dei compiti",
263-
'Japanese': "宿題提出コード開始",
264-
'Nederlands': "Huiswerk inzendcode begint",
265-
'Spanish': "Inicio del código de envío de tareas",
266-
'Thai': "การส่งงานเริ่มต้น",
267-
'Vietnamese': "Bắt đầu mã nộp bài tập",
268-
}
269-
270-
d_homework_end = {
271-
'Korean': "숙제 제출 코드 끝",
272-
'English': "Homework Submission Code End",
273-
'Bahasa Indonesia': "Kode Pengumpulan Tugas Berakhir",
274-
'Chinese': "作业提交代码结束",
275-
'French': '''Fin du code de soumission des devoirs''',
276-
'German': "Ende der Hausaufgaben-Einreichungscodes",
277-
'Italian': "Fine del codice di invio dei compiti",
278-
'Japanese': "宿題提出コード終わり",
279-
'Nederlands': "Huiswerk inzendcode eindigt",
280-
'Spanish': "Fin del código de envío de tareas",
281-
'Thai': "การส่งงานสิ้นสุด",
282-
'Vietnamese': "Mã nộp bài tập kết thúc",
283-
}
252+
def get_instruction_block(readme_file:pathlib.Path, explanation_in:str='Korean',) -> str:
284253

285254
d_instruction_start = {
286255
'Korean': "과제 지침 시작",
@@ -313,15 +282,51 @@ def get_code_instruction(
313282
}
314283

315284
return (
316-
f"\n\n## {d_homework_start[explanation_in]}\n"
317-
f"{assignment_code(student_files)}\n"
318-
f"## {d_homework_end[explanation_in]}\n"
319285
f"## {d_instruction_start[explanation_in]}\n"
320286
f"{assignment_instruction(readme_file)}\n"
321287
f"## {d_instruction_end[explanation_in]}\n"
322288
)
323289

324290

291+
def get_student_code_block(student_files:Tuple[pathlib.Path], explanation_in:str) -> str:
292+
293+
d_homework_start = {
294+
'Korean': "숙제 제출 코드 시작",
295+
'English': "Homework Submission Code Start",
296+
'Bahasa Indonesia': "Kode Pengumpulan Tugas Dimulai",
297+
'Chinese': "作业提交代码开始",
298+
'French': '''Début du code de soumission des devoirs''',
299+
'German': "Code für die Einreichung von Hausaufgaben von hier aus",
300+
'Italian': "Inizio del codice di invio dei compiti",
301+
'Japanese': "宿題提出コード開始",
302+
'Nederlands': "Huiswerk inzendcode begint",
303+
'Spanish': "Inicio del código de envío de tareas",
304+
'Thai': "เริ่มส่งรหัสการบ้าน",
305+
'Vietnamese': "Bắt đầu mã nộp bài tập",
306+
}
307+
308+
d_homework_end = {
309+
'Korean': "숙제 제출 코드 끝",
310+
'English': "Homework Submission Code End",
311+
'Bahasa Indonesia': "Kode Pengumpulan Tugas Berakhir",
312+
'Chinese': "作业提交代码结束",
313+
'French': '''Fin du code de soumission des devoirs''',
314+
'German': "Ende der Hausaufgaben-Einreichungscodes",
315+
'Italian': "Fine del codice di invio dei compiti",
316+
'Japanese': "宿題提出コード終わり",
317+
'Nederlands': "Huiswerk inzendcode eindigt",
318+
'Spanish': "Fin del código de envío de tareas",
319+
'Thai': "จบรหัสส่งการบ้าน",
320+
'Vietnamese': "Mã nộp bài tập kết thúc",
321+
}
322+
323+
return (
324+
f"\n\n## {d_homework_start[explanation_in]}\n"
325+
f"{assignment_code(student_files)}\n"
326+
f"## {d_homework_end[explanation_in]}\n"
327+
)
328+
329+
325330
@functools.lru_cache
326331
def assignment_code(student_files:Tuple[pathlib.Path]) -> str:
327332
return '\n\n'.join([f"# begin : {str(f.name)} ======\n{f.read_text()}\n# end : {str(f.name)} ======\n" for f in student_files])

tests/test_ai_tutor.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,33 +188,42 @@ def instruction(explanation_in:str) -> str:
188188
)
189189

190190

191-
def test_get_code_instruction(
192-
sample_student_code_path:pathlib.Path,
191+
def test_get_instruction_block(
193192
sample_readme_path:pathlib.Path,
194193
explanation_in:str,
195-
homework:Tuple[str],
196194
instruction:str,
197195
):
198196

199-
result = ai_tutor.get_code_instruction(
200-
student_files = (sample_student_code_path,),
197+
result = ai_tutor.get_instruction_block(
201198
readme_file = sample_readme_path,
202199
explanation_in=explanation_in
203200
).lower()
204201

205202
assert any(
206203
map(
207204
lambda x: x in result,
208-
homework
205+
instruction
209206
)
210-
)
207+
), f"Could not find instruction: {instruction} in result: {result}."
208+
209+
210+
def test_get_student_code_block(
211+
sample_student_code_path:pathlib.Path,
212+
explanation_in:str,
213+
homework:Tuple[str],
214+
):
215+
216+
result = ai_tutor.get_student_code_block(
217+
student_files = (sample_student_code_path,),
218+
explanation_in=explanation_in
219+
).lower()
211220

212221
assert any(
213222
map(
214223
lambda x: x in result,
215-
instruction
224+
homework
216225
)
217-
), f"Could not find instruction: {instruction} in result: {result}."
226+
)
218227

219228

220229
def test_get_prompt__has__homework__msg__instruction(

0 commit comments

Comments
 (0)