Added interfaces and helper function to send request for AI marking.

This commit is contained in:
juanpabloacosta
2023-11-30 07:20:37 -05:00
parent 1ff4c1cf1b
commit 498d188925
+42 -1
View File
@@ -151,4 +151,45 @@ export async function getAudio(audioId: string): Promise<Blob> {
const blob = await response.blob();
return blob;
}
}
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<UserQuestionFeedbackResponse> {
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;
}