Skip to content

Commit a153b74

Browse files
committed
Merge branch 'refactor/extract-assignment-specific-instructions'
2 parents 99bd6e8 + 22224a7 commit a153b74

File tree

6 files changed

+333
-17
lines changed

6 files changed

+333
-17
lines changed

CHANGELOG.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased] - YYYY-MM-DD
88

99
### Added
10-
* MECE principle in comment generation
11-
* if failed, assert the error message
12-
* fail-expected argument to fail the test if the expected fail count not correct
1310

1411

1512
### Changed
@@ -24,6 +21,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2421
### Fixed
2522

2623

24+
## [v0.1.6] - 2025-02-01
25+
26+
### Added
27+
* MECE principle in comment generation
28+
* if failed, assert the error message
29+
* `fail-expected` argument to fail the test if the expected fail count not correct
30+
* Add a feature to exclude common content of README.md assignment instruction.
31+
* Common content is marked by the starting marker ``From here is common to all assignments.`` and the ending marker ``Until here is common to all assignments.`` in the README.md file, surrounded by double backtick (ascii 96) characters.
32+
* Add start and end markers to mutable code block in the prompt for Gemini.
33+
34+
35+
### Changed
36+
* Update license to BSD 3-Clause + Do Not Harm.
37+
* Change the default value of `fail-expected` to `false`.
38+
* Improve prompt for Gemini.
39+
* Add header and footer to the prompt.
40+
* Modify instruction for failed tests to "Please generate comments mutually exclusive and collectively exhaustive for the following failed test cases.".
41+
* Add start and end markers to mutable code block.
42+
43+
44+
### Removed
45+
* 'Currently Korean Only' from README.md.
46+
47+
2748
## [v0.1.5] - 2024-10-20
2849

2950
### Added

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Before using this action, ensure you have the following:
2626

2727
## Key Features
2828

29-
* Provide feedback on Python code assignments.
30-
* Support multiple JSON files by pytest-json-report plugin.
29+
* Provide AI powered feedback on Python code assignments.
30+
* Support multiple JSON files by `pytest-json-report` plugin.
3131
* Support multiple student files.
3232

3333
# Usage
@@ -61,6 +61,8 @@ jobs:
6161
6262
```
6363
* This action analyzes the JSON output generated by the `pytest-json-report` plugin to understand the test results of your Python code and provide AI-powered feedback.
64+
* You can exclude common content of README.md assignment instruction to save AI API data usage.
65+
* Please mark the common contents by the starting marker ``From here is common to all assignments.`` and the ending marker ``Until here is common to all assignments.`` in the README.md file, surrounded by double backtick (ascii 96) characters.
6466
6567
## Inputs
6668
* `report-files`: Comma-separated list of JSON report files generated by pytest-json-report. (Required)
@@ -80,12 +82,11 @@ with:
8082
```
8183

8284
## Limitations
83-
* The action currently supports Korean only.
8485
* The action currently supports only Python code assignments.
8586
* The action requires the `pytest-json-report` plugin to generate JSON test reports.
8687

8788
## Future Work
88-
* Support multiple human languages.
89+
* Support more human languages.
8990
* Add language argument
9091
* Add language detection
9192

@@ -96,10 +97,6 @@ with:
9697
* Support more programming languages.
9798
* Possibly in a different repository
9899

99-
* Feedback on code passing all tests.
100-
* Possible further analysis on the code.
101-
* Provide suggestions for further improvements.
102-
103100
* Add `verbose` argument to provide more detailed feedback.
104101
* More internal details
105102

@@ -131,7 +128,7 @@ with:
131128

132129
## License
133130

134-
This project is licensed under the BSD 3-Clause License + Do No Harm.
131+
This project is licensed under the BSD 3-Clause License + Do Not Harm.
135132

136133
Copyright (c) 2024 Kangwon Lee
137134

ai_tutor.py

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import json
33
import logging
44
import pathlib
5+
import re
56
import time
6-
77
from typing import Dict, List, Tuple
88

99
import requests
@@ -238,8 +238,64 @@ def assignment_code(student_files:Tuple[pathlib.Path]) -> str:
238238

239239

240240
@functools.lru_cache
241-
def assignment_instruction(readme_file:pathlib.Path) -> str:
242-
return readme_file.read_text()
241+
def assignment_instruction(
242+
readme_file: pathlib.Path,
243+
common_content_start_marker: str = r"``From here is common to all assignments\.``",
244+
common_content_end_marker: str = r"``Until here is common to all assignments\.``",
245+
) -> str:
246+
"""Extracts assignment-specific instructions from a README.md file.
247+
248+
This function reads a README.md file and removes content marked as common
249+
to all assignments, returning only the assignment-specific instructions.
250+
251+
Args:
252+
readme_file: Path to the README.md file.
253+
common_content_start_marker: The marker indicating the start of common content.
254+
common_content_end_marker: The marker indicating the end of common content.
255+
256+
Returns:
257+
A string containing the assignment-specific instructions.
258+
"""
259+
260+
return exclude_common_contents(
261+
readme_file.read_text(),
262+
common_content_start_marker,
263+
common_content_end_marker,
264+
) # Single exit point
265+
266+
267+
def exclude_common_contents(
268+
readme_content:str,
269+
common_content_start_marker: str = r"``From here is common to all assignments.``",
270+
common_content_end_marker: str = r"``Until here is common to all assignments.``",
271+
) -> str:
272+
"""Removes common content from a string.
273+
274+
This function takes a string and removes the content between the specified
275+
start and end markers.
276+
277+
Args:
278+
readme_content: The input string containing the README content.
279+
common_content_start_marker: The marker indicating the start of common content.
280+
common_content_end_marker: The marker indicating the end of common content.
281+
282+
Returns:
283+
A string with the common content removed.
284+
"""
285+
# Include the markers in the pattern itself
286+
pattern = rf"({common_content_start_marker}\s*.*?\s*{common_content_end_marker})"
287+
found_list = re.findall(pattern, readme_content, re.DOTALL | re.IGNORECASE)
288+
289+
instruction = str(readme_content)
290+
291+
if not found_list:
292+
logging.warning(f"Common content markers '{common_content_start_marker}' and '{common_content_end_marker}' not found in README.md. Returning entire file.")
293+
else:
294+
for found in found_list:
295+
# Remove the common content
296+
instruction = instruction.replace(found, "")
297+
298+
return instruction
243299

244300

245301
@functools.lru_cache(maxsize=None)

entrypoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def main() -> None:
5555
elif b_fail_expected:
5656
assert n_failed > 0, 'No failed tests'
5757
else:
58-
raise NotImplementedError('Unexpected value for INPUT_FAIL-EXPECTED')
58+
raise NotImplementedError('Unexpected value for INPUT_FAIL-EXPECTED')
5959

6060

6161
def get_path_tuple(report_files_str:str) -> Tuple[pathlib.Path]:

0 commit comments

Comments
 (0)