diff --git a/src/routes/api/aiFeedbackOnReport.js b/src/routes/api/aiFeedbackOnReport.js new file mode 100644 index 0000000..902e91a --- /dev/null +++ b/src/routes/api/aiFeedbackOnReport.js @@ -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; \ No newline at end of file diff --git a/src/routes/v1/api.route.js b/src/routes/v1/api.route.js index ad6249d..35fbd67 100644 --- a/src/routes/v1/api.route.js +++ b/src/routes/v1/api.route.js @@ -23,6 +23,7 @@ const getGameScore = require("../api/getGameScore"); const resultAfterQuizSubmit = require("../api/resultAfterQuizSubmit"); const generateQuestions = require("../api/generateQuestions"); const saveGameScore = require("../api/saveGameScore"); +const aiFeedbackOnReport = require("../api/aiFeedbackOnReport"); const router = express.Router(); @@ -142,6 +143,12 @@ router.get("/ping", (req, res) => { saveGameScore(req, res); }); + + // AI feedback for teacher on children's report card + router.post("/aiFeedbackOnReport", (req, res) => { + aiQuestion(req, res); + }); + module.exports = router;