diff --git a/.gitignore b/.gitignore index a50f9ec..6e2c979 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,21 @@ +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local +.env .DS_Store bundle.js diff --git a/README.md b/README.md index a37c9ce..2842879 100644 --- a/README.md +++ b/README.md @@ -14,61 +14,148 @@ At Pensano Developers, we are committed to giving back to our community and supp We work in agile environments, test-driven development, object-oriented programming, and quickly adapting to new tech stacks. We aim to deliver software that meets the needs of the customer, is flexible and adaptable to change, and is delivered efficiently and with high quality. # Getting started + 1. Clone the repo 2. Install Node.js dependencies for both front and backend directories - ```bash - cd backend - npm install - cd ../frontend - npm install - ``` -3. Install the "react-allergens" package using the package manager of your choice, such as npm or yarn. - -To install "react-allergens" using npm: - ```bash - npm install react-allergens - ``` +```bash +cd backend +npm install +cd ../frontend +npm install +``` + +3. Ensure nodemon is installed by running + +```bash +npm install nodemon --global +``` + +4. Install the "react-allergens" package using the package manager of your choice, such as npm or yarn. + To install "react-allergens" using npm: + +```bash +npm install react-allergens +``` + To install "react-allergens" using yarn: - ```bash - yarn add react-allergens - ``` -4. Get a ChatGPT API key - you will need it later. If your team does not have one, you will have to sign in to your ChatGPT account, go to the API keys page and click the “Create new secret key” button. This key should not be visible on GitHub, so we will use a .env file to keep it hidden. Publicly exposing your key can result in your account being compromised, which could lead to unexpected charges on your account. -5. Confirm that `.env` has been added to your `.gitignore` dir +```bash +yarn add react-allergens +``` + +5. Get a ChatGPT API key - you will need it later. If your team does not have one, you will have to sign in to your ChatGPT account, go to the API keys page and click the “Create new secret key” button. This key should not be visible on GitHub, so we will use a .env file to keep it hidden. Publicly exposing your key can result in your account being compromised, which could lead to unexpected charges on your account. + +6. Confirm that `.env` has been added to your `.gitignore` dir + +7. Install dotenv: -6. Install dotenv: ```bash npm install dotenv --save - ``` -7. Create a `.env` file in the backend dir and add `OPENAI_API_KEY=` followed by your ChatGPT API key. It should look like this: - ``` - PROJECT_API_KEY=3ebf52c0-3ebf52c0 - ``` +``` + +8. Create a `.env` file in the backend dir and add `OPENAI_API_KEY=` followed by your ChatGPT API key. It should look like this: + +``` +PROJECT_API_KEY=3ebf52c0-3ebf52c0 +``` ### Running + 1. To start the frontend and backend servers at the same time: - ```bash - cd backend - npm start - ``` +```bash +cd backend +npm start +``` 2. To start the frontend only: - ```bash - cd frontend - npm start - ``` +```bash +cd frontend +npm start +``` 3. To start the backend only: - ```bash - cd backend - npm run server - ``` +```bash +cd backend +npm run server +``` ### Resources + - [MERN Stack: A Comprehensive Guide](https://blog.nextideatech.com/how-to-get-started-with-the-mern-stack-a-comprehensive-guide/) - [Keeping your API keys secret with dotenv](https://jonathansoma.com/lede/foundations-2019/classes/apis/keeping-api-keys-secret/) - [dotenv](https://www.npmjs.com/package/dotenv) + +# Getting Started with Create React App + +This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). + +## Available Scripts + +In the project directory, you can run: + +### `npm start` + +Runs the app in the development mode.\ +Open [http://localhost:3000](http://localhost:3000) to view it in your browser. + +The page will reload when you make changes.\ +You may also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.\ +See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `npm run build` + +Builds the app for production to the `build` folder.\ +It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.\ +Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `npm run eject` + +**Note: this is a one-way operation. Once you `eject`, you can't go back!** + +If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. + +Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. + +You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). + +### Code Splitting + +This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) + +### Analyzing the Bundle Size + +This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) + +### Making a Progressive Web App + +This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) + +### Advanced Configuration + +This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) + +### Deployment + +This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) + +### `npm run build` fails to minify + +This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) diff --git a/backend/controllers/mealPlanController.js b/backend/controllers/mealPlanController.js index 49dcad8..efcad00 100644 --- a/backend/controllers/mealPlanController.js +++ b/backend/controllers/mealPlanController.js @@ -1,28 +1,33 @@ const openai = require("../config/openaiConfig"); -const useOpenAiApi = false; // set to false to use fake data +const useOpenAiApi = true; // set to false to use fake data let mealPlanController; if (useOpenAiApi) { mealPlanController = { generateMealPlan: async (req, res) => { - let { age, allergies, intolerances, diets, otherfood } = req.body; if (intolerances !== "") { - const intolerancesArray = intolerances.split(", ") - allergies.push(...intolerancesArray) + const intolerancesArray = intolerances.split(", "); + allergies.push(...intolerancesArray); } - allergies = allergies.length === 0 ? "no food allergies" : allergies - diets = diets.length === 0 ? "no special diet" : diets - otherfood = otherfood === "" && "no additional foods to include" + allergies = allergies.length === 0 ? "no food allergies" : allergies; + diets = diets.length === 0 ? "no special diet" : diets; + otherfood = otherfood === "" && "no additional foods to include"; - console.log('allergies is', allergies, 'diets is', diets, 'otherfood is', otherfood) + console.log( + "allergies is", + allergies, + "diets is", + diets, + "otherfood is", + otherfood + ); try { - const response = await openai.createChatCompletion({ model: "gpt-3.5-turbo", messages: [ @@ -67,7 +72,7 @@ if (useOpenAiApi) { }, { role: "system", - content: `Do not include any of the following or any foods that contain them: ${allergies}` + content: `Do not include any of the following or any foods that contain them: ${allergies}`, }, { role: "system", @@ -76,19 +81,20 @@ if (useOpenAiApi) { { role: "system", content: `Please include the following foods: ${otherfood}`, - } + }, ], }); // 7-day plan, table format, with the days on top, with an optional snack,and each meal should have the three food groups (protein, carbohydrates and healthy fats) // Send a response back to the client - const gptResponse = response.data.choices[0].message.content + const gptResponse = response.data.choices[0].message.content; res.status(200).json({ gptResponse: gptResponse }); } catch (error) { console.error("Error generating meal plan:", error); - res - .status(500) - .json({ error: "An error occurred while generating the meal plan, please try again later." }); + res.status(500).json({ + error: + "An error occurred while generating the meal plan, please try again later.", + }); } }, }; @@ -96,31 +102,30 @@ if (useOpenAiApi) { mealPlanController = { generateMealPlan: (req, res) => { const mealInputs = req.body; - const gptResponse = "this is fake data" - res.status(200).json({ gptResponse: gptResponse }) - } + const gptResponse = "this is fake data"; + res.status(200).json({ gptResponse: gptResponse }); + }, }; } - module.exports = mealPlanController; // messages: [ - // { - // role: "system", - // content: `I am a nutritional therapist. You are an assistant that - // helps me to generate 7-day meal plans for my clients. I want the meal - // plan to be on a table, with the days of the week across the top and - // the meals on the left-hand column. The meals should include breakfast, - // lunch, dinner and one snack per day. I would like each meal suggestion - // to include the three food groups of protein, carbohydrates and healthy - // fats. Healthy fats include avocado, guacamole dip, salmon, trout, - // mackerel, sardines, chia seeds, nuts, boiled eggs, olive oil, coconut - // oil (for lightly frying), organic butter, ground flaxseeds, hummus, - // and organic milk yoghurt. You should never include processed meats - // (like ham, bacon and salami), biscuits, fries, fish fingers, cakes, - // sweeteners, desserts, soft drinks, ice cream, alcoholic drinks and - // chips. Please adapt the meal plan according to the client's - // characteristics and preferences below.`, - // }, - // ], +// { +// role: "system", +// content: `I am a nutritional therapist. You are an assistant that +// helps me to generate 7-day meal plans for my clients. I want the meal +// plan to be on a table, with the days of the week across the top and +// the meals on the left-hand column. The meals should include breakfast, +// lunch, dinner and one snack per day. I would like each meal suggestion +// to include the three food groups of protein, carbohydrates and healthy +// fats. Healthy fats include avocado, guacamole dip, salmon, trout, +// mackerel, sardines, chia seeds, nuts, boiled eggs, olive oil, coconut +// oil (for lightly frying), organic butter, ground flaxseeds, hummus, +// and organic milk yoghurt. You should never include processed meats +// (like ham, bacon and salami), biscuits, fries, fish fingers, cakes, +// sweeteners, desserts, soft drinks, ice cream, alcoholic drinks and +// chips. Please adapt the meal plan according to the client's +// characteristics and preferences below.`, +// }, +// ], diff --git a/frontend/.gitignore b/frontend/.gitignore index f21726c..25b0f23 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -22,3 +22,72 @@ npm-debug.log* yarn-debug.log* yarn-error.log* + +.DS_Store +bundle.js + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +# next.js build output +.next + +# cypress.io +cypress/screenshots +cypress/videos diff --git a/frontend/README.md b/frontend/README.md deleted file mode 100644 index 20a80ea..0000000 --- a/frontend/README.md +++ /dev/null @@ -1,75 +0,0 @@ -1. Install dependencies in both backend and frontend folders by running `npm install` from both folders -2. Ensure nodemon is installed by running `npm install nodemon --global` -3. Start backend server by running `nodemon server.js` from the backend folder -4. Start the frontend by running `npm start` from the frontend folder - -# Getting Started with Create React App - -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). - -## Available Scripts - -In the project directory, you can run: - -### `npm start` - -Runs the app in the development mode.\ -Open [http://localhost:3000](http://localhost:3000) to view it in your browser. - -The page will reload when you make changes.\ -You may also see any lint errors in the console. - -### `npm test` - -Launches the test runner in the interactive watch mode.\ -See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `npm run build` - -Builds the app for production to the `build` folder.\ -It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.\ -Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `npm run eject` - -**Note: this is a one-way operation. Once you `eject`, you can't go back!** - -If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. - -Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. - -You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). - -### Code Splitting - -This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) - -### Analyzing the Bundle Size - -This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) - -### Making a Progressive Web App - -This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) - -### Advanced Configuration - -This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) - -### Deployment - -This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) - -### `npm run build` fails to minify - -This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)