const aiFeedbackOnReport = async (req, res) => { // const fetch = require('node-fetch'); const url = process.env.AI_API_ENDOINT; const api_key = process.env.AI_API_KEY; const payload = { "model": "gpt-3.5-turbo-16k", "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;