aiFeedbackOnReport

This commit is contained in:
Kar
2024-10-04 22:29:54 +05:30
parent f490aac87e
commit 58805dac6f
7 changed files with 79 additions and 31 deletions

View File

@@ -0,0 +1,34 @@
const aiFeedbackOnReport = async (req, res) => {
const url = process.env.AI_API_ENDOINT;
const api_key = process.env.AI_API_KEY;
const payload = {
"model": "gpt-4o-mini",
"messages": [{ "role": "user",
"content": JSON.stringify(req.body.grades) + " - first dataset(grades) " + JSON.stringify(req.body.suggested) + " - second dataset(suggested actions) " + req.body.instruction }]
}
try {
const apiResponse = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${api_key}`,
// 'Authorization': api_key,
},
body: JSON.stringify(payload)
});
if (!apiResponse.ok) {
return res.status(apiResponse.status).send({ error: 'API response was not ok'+res });
}
const data = await apiResponse.json();
res.send(data);
} catch (error) {
console.error('Error fetching data:', error);
res.status(500).send({ error: 'Something went wrong with the fetch operation' });
}
}
module.exports = aiFeedbackOnReport;

View File

@@ -4,7 +4,7 @@ const aiFeedbackOnReport = async (req, res) => {
const payload = {
"model": "gpt-4o-mini",
"messages": [{ "role": "user",
"content": JSON.stringify(req.body.score) + " - is a sample of a students report card " + req.body.instruction }]
"content": JSON.stringify(req.body.score) + " - is the students report card. " + req.body.instruction }]
}
try {
const apiResponse = await fetch(url, {

View File

@@ -24,6 +24,7 @@ const resultAfterQuizSubmit = require("../api/resultAfterQuizSubmit");
const generateQuestions = require("../api/generateQuestions");
const saveGameScore = require("../api/saveGameScore");
const aiFeedbackOnReport = require("../api/aiFeedbackOnReport");
const aiFeedbackActionParent = require("../api/aiFeedbackActionParent");
const router = express.Router();
@@ -149,6 +150,10 @@ router.get("/ping", (req, res) => {
aiFeedbackOnReport(req, res);
});
// AI top ten action items for a parent of this child.
router.post("/aiFeedbackActionParent", (req, res) => {
aiFeedbackActionParent(req, res);
});
module.exports = router;