Skip to content

Commit e55403d

Browse files
authored
Update classroom.yml
1 parent bf2ad48 commit e55403d

File tree

1 file changed

+45
-26
lines changed

1 file changed

+45
-26
lines changed

.github/workflows/classroom.yml

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,24 @@ jobs:
7272
steps:
7373
- name: Checkout repository
7474
uses: actions/checkout@v5
75+
provide_feedback:
76+
runs-on: ubuntu-latest
77+
permissions:
78+
pull-requests: write
79+
env:
80+
OPENROUTER_MODEL: ${{ vars.OPENROUTER_MODEL }}
81+
SYSTEM_PROMPT: ${{ vars.SYSTEM_PROMPT }}
82+
steps:
83+
- name: Checkout repository
84+
uses: actions/checkout@v5
7585

76-
# 🧠 Read instructions
7786
- name: Read assignment instructions
7887
id: instructions
7988
run: |
89+
# Reads the content of the README.md file into an output variable.
90+
# The `EOF` marker is used to handle multi-line file content.
8091
echo "instructions=$(cat README.md | sed 's/\"/\\\"/g' | sed 's/$/\\n/' | tr -d '\n' | sed 's/\\n/\\\\n/g')" >> $GITHUB_OUTPUT
8192
82-
# 📦 Read source code
8393
- name: Read source code
8494
id: source_code
8595
run: |
@@ -93,7 +103,6 @@ jobs:
93103
echo 'EOF'
94104
} >> "$GITHUB_OUTPUT"
95105
96-
# 🧪 Read test code
97106
- name: Read test code
98107
id: test_code
99108
run: |
@@ -110,14 +119,10 @@ jobs:
110119
fi
111120
echo 'EOF'
112121
} >> "$GITHUB_OUTPUT"
113-
114-
# 🤖 Generate AI Feedback
115122
- name: Generate AI Feedback
116123
id: ai_feedback
117-
env:
118-
OPENROUTER_MODEL: ${{ vars.OPENROUTER_MODEL }}
119-
SYSTEM_PROMPT: ${{ vars.SYSTEM_PROMPT }}
120124
run: |
125+
# This step sends the collected data to the OpenRouter API.
121126
INSTRUCTIONS=$(jq -Rs . <<'EOF'
122127
${{ steps.instructions.outputs.instructions }}
123128
EOF
@@ -130,30 +135,44 @@ jobs:
130135
${{ steps.test_code.outputs.test_code }}
131136
EOF
132137
)
133-
138+
134139
if [ -z "$INSTRUCTIONS" ] || [ -z "$SOURCE_CODE" ] || [ -z "$TEST_CODE" ]; then
135140
echo "Error: One or more required variables are not set."
136-
exit 1
141+
exit 1
137142
fi
138143
139-
PAYLOAD="Please provide feedback on the following Java assignment.\n\n--- Assignment Instructions ---\n${INSTRUCTIONS}\n\n--- Source files ---\n${SOURCE_CODE}\n\n--- Test files ---\n${TEST_CODE}"
140-
144+
# Assigning to USER_CONTENT with variable expansion
145+
PAYLOAD="Please provide feedback on the following Java assignment.
146+
147+
--- Assignment Instructions ---
148+
${INSTRUCTIONS}
149+
150+
--- Source files ---
151+
${SOURCE_CODE}
152+
153+
--- Test files ---
154+
${TEST_CODE}"
155+
141156
JSON_CONTENT=$(jq -n \
142-
--arg model "$OPENROUTER_MODEL" \
143-
--arg system_prompt "$SYSTEM_PROMPT" \
144-
--arg payload "$PAYLOAD" \
145-
'{
146-
models: $model,
147-
messages: [
148-
{role: "system", content: $system_prompt},
149-
{role: "user", content: $payload}
150-
]
151-
}')
152-
157+
--argjson model "$OPENROUTER_MODEL" \
158+
--arg system_prompt "$SYSTEM_PROMPT" \
159+
--arg payload "$PAYLOAD" \
160+
'{
161+
models: $model,
162+
messages: [
163+
{role: "system", content: $system_prompt},
164+
{role: "user", content: $payload}
165+
]
166+
}')
167+
168+
echo "$JSON_CONTENT"
169+
153170
API_RESPONSE=$(echo "$JSON_CONTENT" | curl https://openrouter.ai/api/v1/chat/completions \
154-
-H "Authorization: Bearer ${{ secrets.OPENROUTER_API_KEY }}" \
155-
-H "Content-Type: application/json" \
156-
-d @-)
171+
-H "Authorization: Bearer ${{ secrets.OPENROUTER_API_KEY }}" \
172+
-H "Content-Type: application/json" \
173+
-d @-)
174+
175+
echo "$API_RESPONSE"
157176
158177
FEEDBACK_CONTENT=$(echo "$API_RESPONSE" | jq -r '.choices[0].message.content')
159178
echo "feedback<<EOF" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)