Skip to content

Commit 970d4d6

Browse files
committed
Moves lib code and adds general documentation.
1 parent c706269 commit 970d4d6

File tree

10 files changed

+104
-2
lines changed

10 files changed

+104
-2
lines changed

API.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# API
2+
3+
`GET /`: The root serves as a quick status check.
4+
5+
`GET /test`: Will respond with some kind of successful JSON response.
6+
7+
`GET /openai/models`: Will report back information about the available OpenAI models.
8+
9+
`GET /test/openai`: Will issue a small test prompt to OpenAI's ChatGPT.
10+
11+
* `model`: The model to use. Default: `gpt-3.5-turbo`
12+
* `api-key`: The API key associated with the model.
13+
14+
`POST /assessment`: Issue a rubric assessment to the AI agent and wait for a response.
15+
16+
* `model`: The model to use. Default: `gpt-4`
17+
* `api-key`: The API key associated with the model. Default: the configured key
18+
* `code`: The code to assess. Required.
19+
* `prompt`: The system prompt. Required.
20+
* `rubric`: The rubric, as a CSV. Required.
21+
* `remove-comments`: When `1`, attempts to strip comments out of the code before assessment. Default: 0
22+
* `num-responses`: The number of times it should ask the AI model. It votes on the final answer. Default: 1
23+
* `num-passing-grades`: The number of grades to consider 'passing'. Defaults: 2 (pass fail)
24+
* `temperature`: The 'temperature' value for ChatGPT LLMs.
25+
26+
* **Response**: `application/json`: A list of key concepts, assessment values, and reasons. Example below.
27+
28+
```
29+
[{
30+
"Key Concept": "Program Development 2",
31+
"Observations": "The program uses whitespace good nami [... snipped for brevity ...]. The code is easily readable.",
32+
"Grade": "Extensive Evidence",
33+
"Reason": "The program code effectively uses whitespace, good naming conventions, indentation and comments to make the code easily readable."
34+
}, {
35+
"Key Concept": "Algorithms and Control Structures",
36+
"Observations": "Sprite interactions occur at lines 48-50 (player touches burger), 52 (sw[... snipped for brevity ...]",
37+
"Grade": "Extensive Evidence",
38+
"Reason": "The game includes multiple different interactions between sprites, responds to multiple types of user input (e.g. different arrow keys)."
39+
}]
40+
```
41+
42+
`(GET|POST) /test/assessment`: Issue a test rubric assessment to the AI agent and wait for a response.
43+
44+
* `model`: The model to use. Default: `gpt-4`
45+
* `api-key`: The API key associated with the model. Default: the configured key
46+
* `remove-comments`: When `1`, attempts to strip comments out of the code before assessment. Default: 0
47+
* `num-responses`: The number of times it should ask the AI model. It votes on the final answer. Default: 1
48+
* `num-passing-grades`: The number of grades to consider 'passing'. Defaults: 2 (pass fail)
49+
* `temperature`: The 'temperature' value for ChatGPT LLMs.
50+
51+
* **Response**: `application/json`: A list of key concepts, assessment values, and reasons. See above.

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,42 @@ To Do:
1111
* [ ] create [application cloudformation template](cicd/3-app/aiproxy/template.yml)
1212
* [ ] authentication
1313

14+
## Configuration
15+
16+
The configuration is done via environment variables stored in the `config.txt` file.
17+
18+
For local development, copy the `config.txt.sample` file to `config.txt` to have a
19+
starting point. Then set the `OPENAI_API_KEY` variable to a valid OpenAI API key to
20+
enable that service. Or, otherwise set that variable the appropriate way when
21+
deploying the service.
22+
1423
## Local Development
1524

16-
The Python app exists within "/src"
25+
All of our server code is written using [Flask](https://flask.palletsprojects.com/en/2.3.x/).
26+
27+
The Flask web service exists within "`/src`". The `__init__.py` is the
28+
entry point for the app. The other files provide the routes.
29+
30+
Other related Python code that implement features are within "`/lib`".
31+
32+
To build the app, use `docker compose build`.
33+
You will need to rebuild when you change the source.
1734

1835
To run the app locally, use `docker compose up` from the repo root.
1936

37+
This will run a webserver accessible at [[http://localhost:5000]].
38+
39+
**Note**: You need to provide the API keys in the `config.txt` file
40+
before the service runs. See the above "Configuration" section.
41+
42+
## API
43+
44+
For information about the API, see the [API documentation](API.md).
45+
46+
## Testing
47+
48+
For information about testing the service, see the [Testing documentation](TESTING.md).
49+
2050
## CICD
2151

2252
See [CICD Readme](./cicd/README.md)

TESTING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Testing
2+
3+
You can issue a "test" rubric assessment using hard-coded content that is found in the
4+
`test/data` path by using the `/test/assessment` URL. Here, I'm using `curl` to show
5+
me the headers and send a `POST` to that route (assuming I have the server running):
6+
7+
```
8+
curl localhost:8080/test/assessment -i --header "Content-Type:multipart/form-data" --form "num-responses=3"
9+
```
10+
11+
This gives me this response:
12+
13+
```
14+
HTTP/1.1 200 OK
15+
Content-Length: 2123
16+
Content-Type: text/html; charset=utf-8
17+
Date: Wed, 27 Sep 2023 10:48:36 GMT
18+
Server: waitress
19+
20+
[{"Key Concept": "Program Development 2", "Observations": "The program uses whitespace (e.g., lines 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63), good naming conventions (e.g., \"player\", \"burger\", \"sword\", \"sword2\"), indentation (e.g., lines 20-22, 24-26, 28-30, 32-34, 36-38, 40-42, 44-46, 48-50, 52-54, 56-58, 60-62), and comments (e.g., lines 2, 16, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62). The code is easily readable.", "Grade": "Extensive Evidence", "Reason": "The program code effectively uses whitespace, good naming conventions, indentation and comments to make the code easily readable."}, {"Key Concept": "Algorithms and Control Structures", "Observations": "Sprite interactions occur at lines 48-50 (player touches burger), 52 (sword displaces player), and 53 (sword2 displaces player). The program responds to user input at lines 24-26 (up key), 28-30 (left key), and 32-34 (right key).", "Grade": "Extensive Evidence", "Reason": "The game includes multiple different interactions between sprites, responds to multiple types of user input (e.g. different arrow keys)."}, {"Key Concept": "Position and Movement", "Observations": "The program generates movement at lines 14 (sword), 15 (sword2), 20 (player falling), 24-26 (player moving up), 28-30 (player moving left), 32-34 (player moving right). The movement involves acceleration at lines 20, 24-26, 28-30, 32-34.", "Grade": "Extensive Evidence", "Reason": "Complex movement such as acceleration, moving in a curve, or jumping is included in multiple places in the program."}, {"Key Concept": "Variables", "Observations": "The program updates sprite properties inside the draw loop at lines 20 (player.velocityY), 24-26 (player.velocityY), 28-30 (player.velocityX), 32-34 (player.velocityX), 48-50 (burger.x, burger.y). These updates affect the user's experience of playing the game by controlling the player's movement and the burger's position.", "Grade": "Extensive Evidence", "Reason": "The game includes multiple variables or sprite properties that are updated during the game and affect the user's experience of playing the game."}]
21+
```

lib/assessment/__init__.py

Whitespace-only changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/assessment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import openai
88

99
# Our assessment code
10-
from lib import assess
10+
from lib.assessment import assess
1111

1212
assessment_routes = Blueprint('assessment_routes', __name__)
1313

0 commit comments

Comments
 (0)