aiFeedbackOnReport

This commit is contained in:
Kar
2024-09-20 03:51:26 +05:30
parent 10b7fc5ee2
commit c74a6fd67d
2 changed files with 48 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
const aiFeedbackOnReport = async (req, res) => {
const url = process.env.AI_API_ENDOINT;
const api_key = process.env.AI_API_KEY;
const payload = {
"model": "gpt-3.5-turbo",
"messages": [{ "role": "user",
"content": JSON.stringify(data.score) + "\n above is a sample of a students report card\n" + data.instruction }]
}
try {
// Make the API call using fetch
const apiResponse = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${api_key}`,
// 'Authorization': api_key,
},
body: JSON.stringify(payload)
});
// Check if the response is OK
if (!apiResponse.ok) {
return res.status(apiResponse.status).send({ error: 'API response was not ok' });
}
// Parse the response as JSON
const data = await apiResponse.json();
// Send the API response back to the client
res.send(data);
} catch (error) {
console.error('Error fetching data:', error);
// Send an error response if something goes wrong
res.status(500).send({ error: 'Something went wrong with the fetch operation' });
}
}
module.exports = aiFeedbackOnReport;