-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
839 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ on: | |
paths: | ||
- "**.py" | ||
- "**.requirements.txt" | ||
- "**.package.json" | ||
- "./grader/**" | ||
|
||
env: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,7 +110,7 @@ jobs: | |
id: update_version | ||
run: | | ||
echo "# -*- coding: utf-8 -*-" > ${{ env.VERSION_FILE }} | ||
echo "__version__ = '${{ env.NEXT_VERSION }}'" >> ${{ env.VERSION_FILE }} | ||
echo "__version__ = \"${{ env.NEXT_VERSION }}\"" >> ${{ env.VERSION_FILE }} | ||
echo "" >> ${{ env.VERSION_FILE }} | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
data | ||
|
||
.DS_Store | ||
# Local .terraform directories | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"tabWidth": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,95 @@ | ||
# Canvas Automated Grader | ||
|
||
A Python automatic grader that evaluates JSON files. | ||
A Python automatic grader that evaluates JSON responses from the API end point https://api.openai.lawrencemcdaniel.com/examples/default-marv-sarcastic-chat. Verifies the structural integrity of the JSON response and implements a graduated Rubric based on how closely the response submitted matches this successful [test case](./grader/tests/events/correct.json). | ||
|
||
## Installation | ||
|
||
```console | ||
git clone https://github.com/lpm0073/automatic-grader.git | ||
cd automatic-grader | ||
make init | ||
make activate | ||
``` | ||
|
||
## Usage | ||
|
||
```console | ||
python3 -m grader.batch 'path/to/homework/json/files/' | ||
``` | ||
|
||
### Expected output | ||
|
||
```console | ||
% done! Graded 10 assignments. Output files are in path/to/homework/json/files/out | ||
``` | ||
|
||
```json | ||
{ | ||
"grade": 100, | ||
"message": "Great job!", | ||
"message_type": "Success" | ||
} | ||
``` | ||
|
||
````json | ||
{ | ||
"grade": 80, | ||
"message": "The assignment's statusCode must be 200. received: 403", | ||
"message_type": "ResponseFailedError" | ||
}``` | ||
|
||
```json | ||
{ | ||
"grade": 90, | ||
"message": "The assignment's statusCode must be an integer. received: <class 'str'>", | ||
"message_type": "IncorrectResponseTypeError" | ||
}``` | ||
|
||
```json | ||
{ | ||
"grade": 70, | ||
"message": "The assignment is missing one or more required keys. missing: {'type', 'example', 'additional_kwargs'}", | ||
"message_type": "InvalidResponseStructureError" | ||
}``` | ||
|
||
```json | ||
{ | ||
"grade": 70, | ||
"message": "The messages list must contain at least two elements. messages: [{'content': \"Oh, how delightful. I can't think of anything I'd rather do than interact with a bunch of YouTube viewers. Just kidding, I'd rather be doing literally anything else. But go ahead, introduce me to your lovely audience. I'm sure they'll be absolutely thrilled to meet me.\", 'additional_kwargs': {}, 'type': 'ai', 'example': False}]", | ||
"message_type": "InvalidResponseStructureError" | ||
} | ||
```` | ||
|
||
```json | ||
{ | ||
"grade": 70, | ||
"message": "All elements in the messages list must be dictionaries. messages: ['bad', 'data']", | ||
"message_type": "InvalidResponseStructureError" | ||
} | ||
``` | ||
|
||
```json | ||
{ | ||
"grade": 70, | ||
"message": "The request_meta_data key lambda_langchain must exist. request_meta_data: {}", | ||
"message_type": "InvalidResponseStructureError" | ||
} | ||
``` | ||
|
||
## Contributing | ||
|
||
This project uses a mostly automated pull request and unit testing process. See the resources in .github for additional details. You additionally should ensure that pre-commit is installed and working correctly on your dev machine by running the following command from the root of the repo. | ||
|
||
```console | ||
pre-commit run --all-files | ||
``` | ||
|
||
### Developer setup | ||
|
||
```console | ||
git clone https://github.com/lpm0073/automatic-grader.git | ||
cd automatic-grader | ||
make init | ||
make activate | ||
make test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
__version__ = '1.1.6' | ||
__version__ = '1.2.0' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Batch grader for course assignments.""" | ||
import argparse | ||
import glob | ||
import json | ||
import os | ||
|
||
from .grader import AutomatedGrader | ||
|
||
|
||
def main(filepath: str = None, output_folder: str = "out"): | ||
"""Grade an assignment.""" | ||
graded = 0 | ||
if filepath is None: | ||
print("""usage: grade_assignment.py [-h] filepath""") | ||
|
||
OUTPUT_FILE_PATH = os.path.join(filepath, output_folder) | ||
if not os.path.exists(OUTPUT_FILE_PATH): | ||
os.makedirs(OUTPUT_FILE_PATH) | ||
|
||
assignments = glob.glob(os.path.join(filepath, "*.json")) | ||
for assignment_filename in assignments: | ||
with open(assignment_filename, "r", encoding="utf-8") as f: | ||
try: | ||
assignment = json.load(f) | ||
except json.JSONDecodeError: | ||
print(f"warning: invalid JSON in assignment_filename: {assignment_filename}") | ||
assignment = f.read() | ||
grader = AutomatedGrader(assignment) | ||
grade = grader.grade() | ||
with open( | ||
os.path.join(OUTPUT_FILE_PATH, f"{os.path.basename(assignment_filename)}"), "w", encoding="utf-8" | ||
) as f: | ||
json.dump(grade, f, indent=4) | ||
graded += 1 | ||
|
||
print(f"done! Graded {graded} assignments. Output files are in {OUTPUT_FILE_PATH}") | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Grade a set of homework assignments.") | ||
parser.add_argument("filepath", type=str, help="The path to the homework files to grade.") | ||
parser.add_argument( | ||
"output_folder", | ||
type=str, | ||
nargs="?", # optional | ||
default="out", | ||
help="The name of the subfolder where graded assignments will be saved.", | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
main(args.filepath, args.output_folder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters