From 498d18892539a819bd9c7086e902af088e7c72a2 Mon Sep 17 00:00:00 2001 From: juanpabloacosta Date: Thu, 30 Nov 2023 07:20:37 -0500 Subject: [PATCH] Added interfaces and helper function to send request for AI marking. --- frontend/src/logic/sdk.ts | 43 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/frontend/src/logic/sdk.ts b/frontend/src/logic/sdk.ts index 3188f8d..92e18b0 100644 --- a/frontend/src/logic/sdk.ts +++ b/frontend/src/logic/sdk.ts @@ -151,4 +151,45 @@ export async function getAudio(audioId: string): Promise { const blob = await response.blob(); return blob; -} \ No newline at end of file +} + +export interface UserQuestionRequest +{ + question: string; + user_answer: string; + expected: string; + chapter: string; + language: string; +} + +export interface UserQuestionFeedbackResponse +{ + correct: string; + reason: string; +} + +export async function getAIMarking(question: string, user_answer: string, expected: string, chapter: string, language: string): Promise { + const request: UserQuestionRequest = { + question: question, + user_answer: user_answer, + expected: expected, + chapter: chapter, + language: language + }; + + const response = await fetch(`${backendUrl}/ai-mark`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(request), + }); + + if (!response.ok) { + const errorData = await response.json(); + throw new Error(`HTTP error! status: ${response.status}, message: ${errorData.message}`); + } + + const json = await response.json(); + return json; +}