Skip to main content

How it works

Understanding how a simple Recipe Tool works gives some hints into how AI works under the hood. This isn't an in-depth technical explanation of how AI works; this is an explanation of how to use AI.

1. Input Your Preferences

You start by selecting:

  • Meal Type: Breakfast, Lunch, Dinner, or Snack.
  • Cuisine: American, Japanese, Italian, Indian, or Mexican.
  • Dietary Restrictions: Vegan, Vegetarian, Gluten-Free, etc.

This may not seem like a lot, but customization is critical to getting useful results with AI.

note

It may sound dark, but think of AI as a little like a brain with Alzheimer's. My grandmother got stuck in a loop - she kept purchasing cheese, over and over. And because AI uses pattern recognition, it tends to give the same answers over and over. One way to break the AI out of this loop is to give it variables.

2. The AI system prompt

When you click "Generate Recipe," the tool sends your inputs to the OpenAI GPT-4 model.

But before it does anything, it sends a system prompt. A system prompt instructs the AI to return a recipe in a strict JSON format.

You are a recipe generator. Find a very short recipe for the user 
that matches the following criteria and return the recipe in a
JSON structure. Return only JSON, nothing before or after:

{
"title": "string",
"description": "string",
"prepTimeMinutes": "integer",
"cookTimeMinutes": "integer",
"totalTimeMinutes": "integer",
"ingredients": [
{
"name": "string",
"quantity": "number",
"unit": "string",
"optional": "boolean",
"substitutes": ["string"]
}
],
"instructions": [
{
"stepNumber": "integer",
"description": "string"
}
]
}
info

What is JSON? JSON is a structured data format. As you can see above, it tells the AI exactly what we expect returned.

Of course, you might not want to prompt in JSON. But the most important component is telling the AI exactly what you expect back from it.

3. The user prompt

You, of course, filled out a form. But before I sent that to OpenAI, I turned it into a single prompt:

Find me a brief ${cuisine} recipe for ${meal} with the following restrictions: 
${restrictionsText}. Additional notes: ${notesText}

As you can see, the actual user prompt is quite short. It can be that short, because the system prompt was so robust.

4. Caveats and concerns

If you play with this long enough, you'll note that some of the recipes are not strictly tethered to reality. And that's a big problem with AI. It hallucinates. You can trust it, likely, with a recipe for an egg scramble. But you probably can't trust it with a recipe for a custom carrot cake.

Knowing what AI can and can't be used for is an extraordinarily important part of using AI.