mirror of
https://github.com/jcreek/AutomatedAssessmentFeedbackAgent.git
synced 2026-07-13 11:03:48 +00:00
feat(*): Add AI functionality to grading endpoint
This commit is contained in:
@@ -1,25 +1,40 @@
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
import type { RequestEvent } from '@sveltejs/kit';
|
||||
import { gradeWithOpenAI } from '$lib/utils/ai';
|
||||
|
||||
// TODO - don't just mock the grading logic
|
||||
export const POST: RequestHandler = async (event: RequestEvent) => {
|
||||
const data = await event.request.formData();
|
||||
const file = data.get('file');
|
||||
const text = data.get('text');
|
||||
try {
|
||||
const data = await event.request.formData();
|
||||
const file = data.get('file');
|
||||
const text = data.get('text');
|
||||
let submission = '';
|
||||
|
||||
// Simulation of grading and feedback
|
||||
let feedback = '';
|
||||
if (file) {
|
||||
feedback = 'Received file: ' + (file as File).name + '. [AI feedback coming soon]';
|
||||
} else if (typeof text === 'string' && text.trim().length > 0) {
|
||||
feedback = 'Received text submission. [AI feedback coming soon]';
|
||||
} else {
|
||||
return new Response(JSON.stringify({ error: 'No valid input provided.' }), { 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;
|
||||
if (!fileObj.name.endsWith('.txt')) {
|
||||
return new Response(JSON.stringify({ error: 'Only .txt files are supported at this time.' }), { status: 400 });
|
||||
}
|
||||
const buffer = await fileObj.arrayBuffer();
|
||||
submission = new TextDecoder('utf-8').decode(buffer);
|
||||
} else if (typeof text === 'string' && text.trim().length > 0) {
|
||||
submission = text.trim();
|
||||
} else {
|
||||
return new Response(JSON.stringify({ error: 'No valid input provided.' }), { status: 400 });
|
||||
}
|
||||
|
||||
// Call the AI grading agent
|
||||
const aiResult = await gradeWithOpenAI(submission);
|
||||
|
||||
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}`,
|
||||
...aiResult
|
||||
}), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
} catch (err: any) {
|
||||
return new Response(JSON.stringify({ error: err.message || 'Internal server error.' }), { status: 500 });
|
||||
}
|
||||
|
||||
// Return mock feedback for now
|
||||
return new Response(JSON.stringify({ success: true, feedback }), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user