Skip to main content
Build a dynamic recipe creator using OpenAI’s GPT-4 model. Enter a list of ingredients, and the application returns a chef-quality recipe tailored to your inputs.

Prerequisites

Before you begin, ensure you have:
  • Python 3.7+ installed
  • An OpenAI API key (keep this secret!)
Never hardcode your API key in source files. Use environment variables or a secrets manager.

Install the OpenAI Python SDK

Configure Your API Key

Export your key as an environment variable:
Or set it programmatically:

Collecting Ingredients

Prompt users to input ingredients one at a time. Type done to finish:

Defining the Recipe Generator Function

Create recipe_gen() to format messages for GPT-4 and request a chat completion.

Chat Completion Parameters

Running the Generator

Once ingredients are collected, invoke recipe_gen() and display the result:

Example Session

References

Watch Video