DEV Community

Cover image for I create my daily meal using chat GPT
shrey vijayvargiya
shrey vijayvargiya

Posted on

I create my daily meal using chat GPT

I was testing chat GPT API using Node JS and once the basic endpoint is ready multiple ideas are jumping into my mind.

Watch the video instead of reading -

Do subscribe on Youtube 😁

I was curious to test all of them but I simply can’t because creating frontend interfaces is time-consuming and since chat GPT is not free so I need the user to log in and then add some payment method to use the APIs further.

So the unique and only way to create the endpoint first and test the outcome. In order to create the particular business I first want to test the idea so I post it on the Twitter asap after recording is done.

If you want to learn How to use Chat GPT in Node JS or how to use chat GPT API, below is the video.

Creating Meals using Chat GPT
Coming back to the story, Now I want to create a meal plan. I can have a couple of things to consider such as

  • Country I am from
  • My age
  • Type of meal, vegetarian or not
  • Want to increase or decrease the weight and so on. I create an endpoint that takes the above thing as the parameter and then passes this message to the chat GPT to give me the output in terms of meals.
export const getDataFromOpenAI = async (req, res) => {
 const openai = new OpenAIApi(configuration);
 const { age, increase, amount, unit, meal, vegetarian } = req.body;
 const prompt = `Hello chat GPT my age is ${age} and I want to ${increase ? "increase" : "decrease"} my weight by ${amount} ${unit}, please suggest me daily ${meal} ${vegetarian ? "vegetarian": "non-vegetarian"} meal `;
 const response = await openai.createCompletion({
  model: "text-davinci-003",
  prompt: prompt,
  // instruction: prompt,
  max_tokens: 1000,

 });
 const data = response.data.choices[0].text;
 console.log(response.data.choices, "response")
 res.send(data);
};
Enter fullscreen mode Exit fullscreen mode

I can even create a more customised diet plan including weight, height and other body characteristics. We can even create a frontend interface for users to select and give these properties and get their customised meal accordingly.

Conclusion

That’s it for today, don’t forget to subscribe.

I am testing these small business ideas and regularly posting about them using Open AI and Technology so do subscribe.

See you next time, and have a good day.
Shrey
iHateReading

Top comments (0)