diff --git a/.dockerignore b/.dockerignore index b99e7de..39f75cd 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,6 @@ node_modules .git .gitignore +**/docker-compose* +**/compose.y*ml +**/Dockerfile* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f509987..4e8ce46 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 ./ @@ -12,4 +16,6 @@ RUN yarn install --pure-lockfile COPY --chown=node:node . . -EXPOSE 3000 +EXPOSE 5174 + +CMD yarn start \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index a6ff511..da09613 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,32 +1,31 @@ -version: '3' - services: - node-app: + iimtt_api: build: . - image: node-app - environment: - - MONGODB_URL=mongodb://mongodb:27017/node-boilerplate + image: iimtt_api + # environment: + # - MONGODB_URL=mongodb://mongodb:27017/node-boilerplate ports: - - '3000:3000' - depends_on: - - mongodb + - '5174:5174' + # depends_on: + # - mongodb volumes: - - .:/usr/src/node-app - networks: - - node-network + - .:/usr/src/iimtt_api + # networks: + # - host +# - node-network - mongodb: - image: mongo:4.2.1-bionic - ports: - - '27017:27017' - volumes: - - dbdata:/data/db - networks: - - node-network +# mongodb: +# image: mongo:4.2.1-bionic +# ports: +# - '27017:27017' +# volumes: +# - dbdata:/data/db +# networks: +# - node-network -volumes: - dbdata: +# volumes: +# dbdata: -networks: - node-network: - driver: bridge +# networks: +# node-network: +# driver: bridge diff --git a/package.json b/package.json index 3e6cb2f..088d4ba 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "node": ">=12.0.0" }, "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", "test": "jest -i --colors --verbose --detectOpenHandles", "test:watch": "jest -i --watchAll", diff --git a/src/routes/api/aiFeedbackActionParent.js b/src/routes/api/aiFeedbackActionParent.js new file mode 100644 index 0000000..4c09ec4 --- /dev/null +++ b/src/routes/api/aiFeedbackActionParent.js @@ -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; \ No newline at end of file diff --git a/src/routes/api/aiFeedbackOnReport.js b/src/routes/api/aiFeedbackOnReport.js index 474849c..ff02fca 100644 --- a/src/routes/api/aiFeedbackOnReport.js +++ b/src/routes/api/aiFeedbackOnReport.js @@ -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, { diff --git a/src/routes/v1/api.route.js b/src/routes/v1/api.route.js index 014fc60..4191909 100644 --- a/src/routes/v1/api.route.js +++ b/src/routes/v1/api.route.js @@ -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;