Skip to content

Commit a08c998

Browse files
committed
replace human_language with explanation_in
1 parent a2443be commit a08c998

2 files changed

Lines changed: 33 additions & 33 deletions

File tree

ai_tutor.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def gemini_qna(
8787
student_files:List[pathlib.Path],
8888
readme_file:pathlib.Path,
8989
api_key:str,
90-
human_language:str='Korean',
90+
explanation_in:str='Korean',
9191
) -> str:
9292
'''
9393
Queries the Gemini API to provide explanations for failed pytest test cases.
@@ -109,7 +109,7 @@ def gemini_qna(
109109
report_paths,
110110
student_files,
111111
readme_file,
112-
human_language
112+
explanation_in
113113
)
114114

115115
answers = ask_gemini(consolidated_question, api_key)
@@ -121,7 +121,7 @@ def get_the_question(
121121
report_paths:Tuple[pathlib.Path],
122122
student_files:Tuple[pathlib.Path],
123123
readme_file:pathlib.Path,
124-
human_language:str,
124+
explanation_in:str,
125125
) -> str:
126126
questions = []
127127

@@ -145,10 +145,10 @@ def get_initial_instruction(questions:List[str],language:str) -> str:
145145

146146
questions = (
147147
# Add the initial instruction
148-
[get_initial_instruction(questions, human_language), get_report_header(human_language)]
148+
[get_initial_instruction(questions, explanation_in), get_report_header(explanation_in)]
149149
+ questions
150150
# Add the code and instructions
151-
+ [get_report_footer(human_language), get_code_instruction(student_files, readme_file, human_language)]
151+
+ [get_report_footer(explanation_in), get_code_instruction(student_files, readme_file, explanation_in)]
152152
)
153153

154154
# Join all questions into a single string
@@ -158,7 +158,7 @@ def get_initial_instruction(questions:List[str],language:str) -> str:
158158

159159

160160
@functools.lru_cache
161-
def get_directive(human_language:str) -> str:
161+
def get_directive(explanation_in:str) -> str:
162162
d = {
163163
'Korean': '숙제 답안으로 제출한 코드가 오류를 일으킨 원인을 입문자 용어만으로 중복 없는 간결한 문장으로 설명하시오.',
164164
'English': 'Explain in beginner terms, without duplicates, the cause of the error in the code submitted as homework.',
@@ -169,7 +169,7 @@ def get_directive(human_language:str) -> str:
169169
'German': 'Erklären Sie in Anfängerterminologie ohne Duplikate die Ursache des Fehlers im als Hausaufgabe eingereichten Code.',
170170
'Thai': 'อธิบายด้วยภาษาของผู้เริ่มต้นโดยไม่ซ้ำซ้อนว่าสาเหตุของข้อผิดพลาดในรหัสที่ส่งเป็นการบ้านคืออะไร',
171171
}
172-
return f"{d[human_language]}\n"
172+
return f"{d[explanation_in]}\n"
173173

174174

175175
def collect_longrepr(data:Dict[str, str]) -> List[str]:
@@ -184,14 +184,14 @@ def collect_longrepr(data:Dict[str, str]) -> List[str]:
184184

185185

186186
@functools.lru_cache
187-
def get_question(longrepr:str, human_language:str,) -> str:
187+
def get_question(longrepr:str, explanation_in:str,) -> str:
188188
return (
189-
get_report_header(human_language) + f"{longrepr}\n" + get_report_footer(human_language)
189+
get_report_header(explanation_in) + f"{longrepr}\n" + get_report_footer(explanation_in)
190190
)
191191

192192

193193
@functools.lru_cache
194-
def get_report_header(human_language:str) -> str:
194+
def get_report_header(explanation_in:str) -> str:
195195
d = {
196196
'Korean': "오류 메시지 시작",
197197
'English': "Error Message Start",
@@ -203,12 +203,12 @@ def get_report_header(human_language:str) -> str:
203203
'Thai': "ข้อความผิดพลาดเริ่มต้น",
204204
}
205205
return (
206-
f"## {d[human_language]}\n"
206+
f"## {d[explanation_in]}\n"
207207
)
208208

209209

210210
@functools.lru_cache
211-
def get_report_footer(human_language:str) -> str:
211+
def get_report_footer(explanation_in:str) -> str:
212212
d = {
213213
'Korean': "오류 메시지 끝",
214214
'English': "Error Message End",
@@ -220,15 +220,15 @@ def get_report_footer(human_language:str) -> str:
220220
'Thai': "ข้อความผิดพลาดสิ้นสุด",
221221
}
222222
return (
223-
f"## {d[human_language]}\n"
223+
f"## {d[explanation_in]}\n"
224224
)
225225

226226

227227
@functools.lru_cache
228228
def get_code_instruction(
229229
student_files:Tuple[pathlib.Path],
230230
readme_file:pathlib.Path,
231-
human_language:str,
231+
explanation_in:str,
232232
) -> str:
233233

234234
d_homework_start = {
@@ -276,12 +276,12 @@ def get_code_instruction(
276276
}
277277

278278
return (
279-
f"\n\n## {d_homework_start[human_language]}\n"
279+
f"\n\n## {d_homework_start[explanation_in]}\n"
280280
f"{assignment_code(student_files)}\n"
281-
f"## {d_homework_end[human_language]}\n"
282-
f"## {d_instruction_start[human_language]}\n"
281+
f"## {d_homework_end[explanation_in]}\n"
282+
f"## {d_instruction_start[explanation_in]}\n"
283283
f"{assignment_instruction(readme_file)}\n"
284-
f"## {d_instruction_end[human_language]}\n"
284+
f"## {d_instruction_end[explanation_in]}\n"
285285
)
286286

287287

tests/test_ai_tutor.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ def test_collect_longrepr(json_dict_div_zero_try_except:Dict):
5858

5959

6060
@pytest.fixture(params=('Korean', 'English', 'Japanese', 'Chinese', 'Spanish', 'French', 'German', 'Thai'))
61-
def human_language(request) -> str:
61+
def explanation_in(request) -> str:
6262
return request.param.capitalize()
6363

6464

6565
@pytest.fixture
66-
def homework(human_language:str) -> str:
66+
def homework(explanation_in:str) -> str:
6767
d = {
6868
'Korean': '숙제',
6969
'English': 'Homework',
@@ -74,11 +74,11 @@ def homework(human_language:str) -> str:
7474
'German': 'Hausaufgabe',
7575
'Thai': 'การบ้าน',
7676
}
77-
return d[human_language].lower()
77+
return d[explanation_in].lower()
7878

7979

8080
@pytest.fixture
81-
def msg(human_language:str) -> str:
81+
def msg(explanation_in:str) -> str:
8282
d = {
8383
'Korean': '메시지',
8484
'English': 'Message',
@@ -89,19 +89,19 @@ def msg(human_language:str) -> str:
8989
'German': 'Fehlermeldung',
9090
'Thai': 'ข้อความ',
9191
}
92-
return d[human_language].lower()
92+
return d[explanation_in].lower()
9393

9494

95-
def test_get_instruction(human_language, homework,):
96-
result = ai_tutor.get_directive(human_language=human_language)
95+
def test_get_instruction(explanation_in, homework,):
96+
result = ai_tutor.get_directive(explanation_in=explanation_in)
9797

9898
assert homework in result.lower()
9999

100100

101101
@pytest.mark.parametrize("func", (ai_tutor.get_report_header, ai_tutor.get_report_footer))
102-
def test_get_report__header__footer(human_language, msg, func):
102+
def test_get_report__header__footer(explanation_in, msg, func):
103103

104-
result = func(human_language=human_language)
104+
result = func(explanation_in=explanation_in)
105105

106106
assert msg in result.lower()
107107

@@ -117,7 +117,7 @@ def sample_readme_path() -> pathlib.Path:
117117

118118

119119
@pytest.fixture
120-
def instruction(human_language:str) -> str:
120+
def instruction(explanation_in:str) -> str:
121121
d = {
122122
'Korean': '지침',
123123
'English': 'Instruction',
@@ -128,21 +128,21 @@ def instruction(human_language:str) -> str:
128128
'German': 'Aufgabenanweisung',
129129
'Thai': 'แนะนำ',
130130
}
131-
return d[human_language].lower()
131+
return d[explanation_in].lower()
132132

133133

134134
def test_get_code_instruction(
135135
sample_student_code_path:pathlib.Path,
136136
sample_readme_path:pathlib.Path,
137-
human_language:str,
137+
explanation_in:str,
138138
homework:str,
139139
instruction:str,
140140
):
141141

142142
result = ai_tutor.get_code_instruction(
143143
student_files = (sample_student_code_path,),
144144
readme_file = sample_readme_path,
145-
human_language=human_language
145+
explanation_in=explanation_in
146146
).lower()
147147

148148
assert homework in result
@@ -154,15 +154,15 @@ def test_get_the_question(
154154
div_zero_report_path:pathlib.Path,
155155
sample_student_code_path:pathlib.Path,
156156
sample_readme_path:pathlib.Path,
157-
human_language:str,
157+
explanation_in:str,
158158
homework:str, msg:str,
159159
instruction:str,
160160
):
161161
result = ai_tutor.get_the_question(
162162
report_paths=(sample_report_path,div_zero_report_path),
163163
student_files=(sample_student_code_path,),
164164
readme_file=sample_readme_path,
165-
human_language=human_language,
165+
explanation_in=explanation_in,
166166
).lower()
167167

168168
assert homework in result

0 commit comments

Comments
 (0)