Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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

Expand Down
157 changes: 122 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a known issue here with nodemon? I did note that nodemon is listed as a dependency where I believe it should be a dev dependency which could potentially be an issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, yesterday we noticed nodemon appearing in a few error messages. We might need to update it to be a dev dependency then.


```bash
npm install nodemon --global
```

4. Install the "react-allergens" package using the package manager of your choice, such as npm or yarn.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to nodemon, but why do we need this when it is already a dependency? Is there any known issue here? If there is then we should be expected to have a production issue with it.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm all in favour of ditching the default React App documentation as it feels like unnecessary information for this project. If we are keeping it then line 98, "In the project directory, you can run:" is no longer true and line 100, "### npm start" is repetition.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Another thing we added yesterday was to set our ‘OPENAI_API_KEY’ Environment Variable using zsh:

  1. Run the following command in your terminal, replacing yourkey with your API key.

echo "export OPENAI_API_KEY='yourkey'" >> ~/.zshrc

  1. Update the shell with the new variable:

source ~/.zshrc

  1. Confirm that you have set your environment variable using the following command.

echo $OPENAI_API_KEY
The value of your API key will be the resulting output.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make the changes and let you know.


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)
79 changes: 42 additions & 37 deletions backend/controllers/mealPlanController.js
Original file line number Diff line number Diff line change
@@ -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: [
Expand Down Expand Up @@ -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",
Expand All @@ -76,51 +81,51 @@ 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.",
});
}
},
};
} else {
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.`,
// },
// ],
Loading