diff --git a/src/lib/utils/ai.ts b/src/lib/utils/ai.ts index 79fbf49..4005d3d 100644 --- a/src/lib/utils/ai.ts +++ b/src/lib/utils/ai.ts @@ -5,8 +5,16 @@ const OPENAI_ENDPOINT = process.env['AZURE_OPENAI_ENDPOINT']; const OPENAI_DEPLOYMENT = process.env['AZURE_OPENAI_DEPLOYMENT'] || 'gpt-4'; // Prompt template for grading and feedback -export function buildGradingPrompt(submission: string) { - return `You are an expert secondary school teacher and AI assessment agent. Assess the following student submission using the following steps: +export function buildGradingPrompt(submission: string, task: string) { + return `You are an expert secondary school teacher and AI assessment agent. Assess the following student submission in the context of the assignment/task provided. + +TASK/ASSIGNMENT: +${task} + +STUDENT SUBMISSION: +${submission} + +Follow these steps: 1. Grade the work out of 10, using clear, objective criteria. 2. Identify specific strengths, referencing the success criteria. 3. Identify misconceptions or areas for improvement, using formative assessment language. @@ -18,9 +26,6 @@ export function buildGradingPrompt(submission: string) { 6. Suggest to the teacher one way to support this student in the next lesson. 7. Show your reasoning step by step (chain-of-thought). -STUDENT SUBMISSION: -${submission} - RESPONSE FORMAT: Grade: /10 Strengths: @@ -31,12 +36,12 @@ Teacher Suggestion: Reasoning: `; } -export async function gradeWithOpenAI(submission: string): Promise { +export async function gradeWithOpenAI(submission: string, task: string): Promise { if (!OPENAI_API_KEY || !OPENAI_ENDPOINT) { // Fallback for local/demo mode return { grade: '7/10', - strengths: 'Clear argument and good evidence.', + strengths: 'Clear argument and good evidence (in response to the task: ' + task + ").", areas_for_improvement: 'Needs deeper analysis and more examples.', individualized_activity: 'Write a paragraph expanding on your main point and provide two additional examples to support your argument.', reflection_question: 'What was the most challenging part of this assignment for you, and why?', @@ -45,7 +50,7 @@ export async function gradeWithOpenAI(submission: string): Promise { const data = await event.request.formData(); const file = data.get('file'); const text = data.get('text'); + const task = data.get('task'); let submission = ''; + if (!task || typeof task !== 'string' || !task.trim()) { + return new Response(JSON.stringify({ error: 'Task/assignment description is required.' }), { status: 400 }); + } + if (file && typeof file === 'object' && 'arrayBuffer' in file && 'name' in file) { // Only support .txt for now for hackathon speed const fileObj = file as File; @@ -24,11 +29,12 @@ export const POST: RequestHandler = async (event: RequestEvent) => { } // Call the AI grading agent - const aiResult = await gradeWithOpenAI(submission); + const aiResult = await gradeWithOpenAI(submission, task.trim()); return new Response(JSON.stringify({ success: true, - feedback: `Grade: ${aiResult.grade}\nStrengths: ${aiResult.strengths}\nWeaknesses: ${aiResult.weaknesses}\nIndividualized Activity: ${aiResult.individualized_activity}\nReasoning: ${aiResult.reasoning}`, + task: task.trim(), + feedback: `Grade: ${aiResult.grade}\nStrengths: ${aiResult.strengths}\nAreas for Improvement: ${aiResult.areas_for_improvement}\nIndividualized Activity: ${aiResult.individualized_activity}\nReasoning: ${aiResult.reasoning}`, ...aiResult }), { status: 200, diff --git a/src/routes/upload/+page.svelte b/src/routes/upload/+page.svelte index 3f4cf9b..351fb1f 100644 --- a/src/routes/upload/+page.svelte +++ b/src/routes/upload/+page.svelte @@ -3,6 +3,7 @@ import { onMount } from 'svelte'; let file: File | null = null; let textInput = ''; +let taskDescription = ''; let submitting = false; let successMsg = ''; let errorMsg = ''; @@ -33,7 +34,13 @@ async function handleSubmit(event: Event) { successMsg = ''; errorMsg = ''; + if (!taskDescription.trim()) { + errorMsg = 'Please provide a description of the task or assignment.'; + submitting = false; + return; + } const formData = new FormData(); + formData.append('task', taskDescription.trim()); if (file) { formData.append('file', file); } else if (textInput.trim().length > 0) { @@ -52,6 +59,7 @@ async function handleSubmit(event: Event) { window.location.assign('/results'); file = null; textInput = ''; + taskDescription = ''; return; } else { errorMsg = result.error || 'An error occurred.'; @@ -68,43 +76,44 @@ async function handleSubmit(event: Event) {

Upload Student Submissions

Upload student assignments for instant AI-powered assessment and feedback.

-
-
- + +

Upload Student Submission

+
+ + +
+
+ + Or paste the student's submission below.
-
or
-
- +
+
+ {#if errorMsg} -
{errorMsg}
+
{errorMsg}
{/if} {#if successMsg} -
{successMsg}
+
{successMsg}
{/if} -