Skip to content

Commit 73b482b

Browse files
committed
Merge branch 'xml-tag-clean' of https://github.com/Rolland-He/ai-autograding-feedback into xml-tag-clean
2 parents 654a8ef + b95fb53 commit 73b482b

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

ai_feedback/helpers/template_utils.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,46 +85,48 @@ def gather_file_references(submission: Optional[Path], solution: Optional[Path],
8585
return "\n".join(references)
8686

8787

88-
def gather_xml_file_contents(submission: Path, solution: Optional[Path] = None, test_output: Optional[Path] = None) -> str:
88+
def gather_xml_file_contents(
89+
submission: Path, solution: Optional[Path] = None, test_output: Optional[Path] = None
90+
) -> str:
8991
"""Generate file contents with XML tags for prompt templates.
9092
9193
Args:
9294
submission (Path): Student's submission file path
93-
solution (Path, optional): Instructor's solution file path
95+
solution (Path, optional): Instructor's solution file path
9496
test_output (Path, optional): Student's test output file path
9597
9698
Returns:
9799
str: File contents formatted with XML tags and line numbers
98100
"""
99101
file_contents = ""
100-
102+
101103
file_contents += _format_file_with_xml_tag(submission, "submission")
102104

103105
if solution:
104106
file_contents += _format_file_with_xml_tag(solution, "solution")
105107

106108
if test_output:
107109
file_contents += _format_file_with_xml_tag(test_output, "test_output")
108-
110+
109111
return file_contents
110112

111113

112114
def _format_file_with_xml_tag(file_path: Path, tag_name: str) -> str:
113115
"""Format a single file with XML tags and line numbers.
114-
116+
115117
Args:
116118
file_path (Path): Path to the file to format
117119
tag_name (str): The XML tag name (submission, solution, test_output)
118-
120+
119121
Returns:
120122
str: Formatted file content with XML tags
121123
"""
122124
if not file_path:
123125
return ""
124-
126+
125127
filename = os.path.basename(file_path)
126128
content = ""
127-
129+
128130
try:
129131
# Handle PDF files separately
130132
if filename.lower().endswith('.pdf'):
@@ -276,7 +278,7 @@ def _get_question_contents(assignment_files: List[Optional[Path]], question_num:
276278
"""
277279
file_contents = ""
278280
task_found = False
279-
281+
280282
semantic_tags = ["submission", "solution"]
281283

282284
for index, file_path in enumerate(assignment_files):

tests/open_ai_model_tests/integration_test.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,20 @@ def test_xml_formatting_code_scope(capsys, mock_and_capture):
9595
args = [
9696
"--prompt_text",
9797
"File references: {file_references}\n\nFile contents:\n{file_contents}",
98-
"--scope",
98+
"--scope",
9999
"code",
100100
"--submission",
101101
str(parent / "test_submissions/csc108/correct_submission/correct_submission.py"),
102102
"--solution",
103103
str(parent / "test_submissions/csc108/solution.py"),
104104
"--model",
105-
"openai"
105+
"openai",
106106
]
107107
output = run_cli_and_capture(args, capsys)
108-
108+
109109
assert "The student's submission file is correct_submission.py." in output
110110
assert "The instructor's solution file is solution.py." in output
111-
111+
112112
assert '<submission file="correct_submission.py">' in output
113113
assert '</submission>' in output
114114
assert '<solution file="solution.py">' in output
@@ -130,19 +130,19 @@ def test_xml_formatting_text_scope_with_test_output(capsys, mock_and_capture):
130130
"--submission_type",
131131
"python",
132132
"--scope",
133-
"text",
133+
"text",
134134
"--submission",
135135
str(parent / "test_submissions/ggr274_homework5/test1/student_submission.txt"),
136136
"--solution",
137137
str(parent / "test_submissions/ggr274_homework5/test1/Homework_5_solution.txt"),
138138
"--model",
139-
"openai"
139+
"openai",
140140
]
141141
output = run_cli_and_capture(args, capsys)
142-
142+
143143
assert "The student's submission file is student_submission.txt." in output
144-
assert "The instructor's solution file is Homework_5_solution.txt." in output
145-
144+
assert "The instructor's solution file is Homework_5_solution.txt." in output
145+
146146
assert '<submission file="student_submission.txt">' in output
147147
assert '</submission>' in output
148148
assert '<solution file="Homework_5_solution.txt">' in output

0 commit comments

Comments
 (0)