aiFeedbackOnReport

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

View File

@ -1,3 +1,6 @@
node_modules node_modules
.git .git
.gitignore .gitignore
**/docker-compose*
**/compose.y*ml
**/Dockerfile*

View File

@ -1,8 +1,12 @@
FROM node:alpine ARG NODE_VERSION=18
RUN mkdir -p /usr/src/node-app && chown -R node:node /usr/src/node-app FROM node:${NODE_VERSION}-alpine
WORKDIR /usr/src/node-app ENV NODE_ENV production
RUN mkdir -p /usr/src/iimtt_api && chown -R node:node /usr/src/iimtt_api
WORKDIR /usr/src/iimtt_api
COPY package.json yarn.lock ./ COPY package.json yarn.lock ./
@ -12,4 +16,6 @@ RUN yarn install --pure-lockfile
COPY --chown=node:node . . COPY --chown=node:node . .
EXPOSE 3000 EXPOSE 5174
CMD yarn start

View File

@ -1,32 +1,31 @@
version: '3'
services: services:
node-app: iimtt_api:
build: . build: .
image: node-app image: iimtt_api
environment: # environment:
- MONGODB_URL=mongodb://mongodb:27017/node-boilerplate # - MONGODB_URL=mongodb://mongodb:27017/node-boilerplate
ports: ports:
- '3000:3000' - '5174:5174'
depends_on: # depends_on:
- mongodb # - mongodb
volumes: volumes:
- .:/usr/src/node-app - .:/usr/src/iimtt_api
networks: # networks:
- node-network # - host
# - node-network
mongodb: # mongodb:
image: mongo:4.2.1-bionic # image: mongo:4.2.1-bionic
ports: # ports:
- '27017:27017' # - '27017:27017'
volumes: # volumes:
- dbdata:/data/db # - dbdata:/data/db
networks: # networks:
- node-network # - node-network
volumes: # volumes:
dbdata: # dbdata:
networks: # networks:
node-network: # node-network:
driver: bridge # driver: bridge

View File

@ -9,7 +9,8 @@
"node": ">=12.0.0" "node": ">=12.0.0"
}, },
"scripts": { "scripts": {
"start": "pm2 start ecosystem.config.json --no-daemon", "start": "NODE_ENV=production node src/index.js",
"start:pm2": "pm2 start ecosystem.config.json --no-daemon",
"dev": "cross-env NODE_ENV=development nodemon src/index.js", "dev": "cross-env NODE_ENV=development nodemon src/index.js",
"test": "jest -i --colors --verbose --detectOpenHandles", "test": "jest -i --colors --verbose --detectOpenHandles",
"test:watch": "jest -i --watchAll", "test:watch": "jest -i --watchAll",

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 = { const payload = {
"model": "gpt-4o-mini", "model": "gpt-4o-mini",
"messages": [{ "role": "user", "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 { try {
const apiResponse = await fetch(url, { const apiResponse = await fetch(url, {

View File

@ -24,6 +24,7 @@ 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 aiFeedbackOnReport = require("../api/aiFeedbackOnReport");
const aiFeedbackActionParent = require("../api/aiFeedbackActionParent");
const router = express.Router(); const router = express.Router();
@ -149,6 +150,10 @@ router.get("/ping", (req, res) => {
aiFeedbackOnReport(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; module.exports = router;