Skip to content

Commit 5d718df

Browse files
authored
Create AI_INTEGRATION_README.md
1 parent 347b45b commit 5d718df

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

AI_INTEGRATION_README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# AI Feedback Integration in CodeOcean
2+
3+
This project integrates ChatGPT into CodeOcean to provide automated feedback for both **Request for Comments (RFCs)** and **test results**.
4+
5+
## Prerequisites
6+
7+
- **ChatGPT API Key:** Stored securely via Rails credentials
8+
- **Internal User:** Requires an internal user (`[email protected]`) to create comments
9+
- **Gem Required:** `gem 'ruby-openai'`
10+
11+
## Overview
12+
13+
- **AI API:** OpenAI Chat Completions
14+
- **Jobs:** Asynchronous processing via Solid Queue
15+
- **Frontend:** Adds "Request Feedback from AI" buttons for students
16+
17+
## Key Components
18+
19+
### ChatGPT Service
20+
21+
Encapsulates API communication with ChatGPT.
22+
23+
- **Implementation:** `app/services/chat_gpt_service/chat_gpt_request.rb`
24+
- **Prompt files:** `app/services/chat_gpt_service/chat_gpt_prompts/` (EN and DE versions)
25+
- **Structured Output Schema:** `app/services/chat_gpt_service/chat_gpt_prompts/response_format.json`
26+
27+
**Key Method:**
28+
- `execute(prompt, structured_output)`: Sends prompt and receives response
29+
30+
### ChatGPT Helper
31+
32+
Responsible for formatting prompts and parsing responses.
33+
34+
- `format_prompt`: Loads locale-specific templates and replaces placeholders in the prompt from application
35+
- `format_response`: Parses structured JSON response from chatGPT to create general commenta(line 0) and line comments for RFC.
36+
37+
### Automatic Comment Job (RFC)
38+
39+
Handles background comment generation when students submit a Request for Comments.
40+
41+
- **Job class:** `GenerateAutomaticCommentsJob`
42+
- **Service:** Uses `ChatGptRequest` to communicate with the API
43+
- **Process:**
44+
1. Prompts are built from student code and context
45+
2. API response is parsed
46+
3. General and line-specific comments are created
47+
4. Emails are sent using Solid Queue
48+
49+
### ️Request Feedback From AI
50+
51+
Allows students to request feedback per test result after scoring.
52+
53+
- **Output modification:**
54+
`app/models/submission.rb`
55+
Adds `testrun_id` to each test result:
56+
```ruby
57+
output.merge!(filename:, message: feedback_message(file, output), weight: file.weight, hidden_feedback: file.hidden_feedback, testrun_id: testrun.id)
58+
```
59+
60+
- **Frontend integration:**
61+
`app/assets/javascripts/editor/editor.js.erb`
62+
Adds data attribute to each test result card:
63+
```js
64+
card.attr('data-testrun-id', result.testrun_id); // Add testrun_id to the card
65+
```
66+
67+
- **Triggering feedback request:**
68+
`app/assets/javascripts/editor.js`
69+
Handles button click, calls backend route, and updates the UI with the ChatGPT feedback.
70+
71+
- **Route and logic:**
72+
- `app/controllers/submissions_controller.rb`: Handles `/testrun_ai_feedback_message` route
73+
- `app/models/testrun.rb`: Contains `generate_ai_feedback` method that builds prompt and fetches response
74+
75+
### Exercise-Level Controls
76+
77+
Instructors can toggle AI features per exercise using boolean flags:
78+
79+
- `allow_ai_comment_for_rfc`: Enables RFC-based AI feedback
80+
- `allow_ai_feedback_on_score`: Enables test-based feedback
81+
82+
83+
---

0 commit comments

Comments
 (0)