aiFeedbackOnReport
parent
10b7fc5ee2
commit
c74a6fd67d
|
@ -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;
|
|
@ -23,6 +23,7 @@ const getGameScore = require("../api/getGameScore");
|
||||||
const resultAfterQuizSubmit = require("../api/resultAfterQuizSubmit");
|
const resultAfterQuizSubmit = require("../api/resultAfterQuizSubmit");
|
||||||
const generateQuestions = require("../api/generateQuestions");
|
const generateQuestions = require("../api/generateQuestions");
|
||||||
const saveGameScore = require("../api/saveGameScore");
|
const saveGameScore = require("../api/saveGameScore");
|
||||||
|
const aiFeedbackOnReport = require("../api/aiFeedbackOnReport");
|
||||||
|
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
@ -143,6 +144,12 @@ router.get("/ping", (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// AI feedback for teacher on children's report card
|
||||||
|
router.post("/aiFeedbackOnReport", (req, res) => {
|
||||||
|
aiQuestion(req, res);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue