Function Repository Resource:

RecipeGraph (1.0.0) current version: 1.1.0 »

Source Notebook

Create a graph of the ingredients and instructions for a recipe

Contributed by: Gay Wilson and Tommy Peters

ResourceFunction["RecipeGraph"][recipe]

returns a directed graph of the ingredients and instructions for a recipe.

Details and Options

ResourceFunction["RecipeGraph"] relies on a large language model (LLM) and requires an API key.
You can check whether an API Key is set by evaluating SystemCredential["your keyname"]. If needed, the key can be set using SystemCredential["your keyname"]="your-key-here".
The recipe ingredients and instructions form the vertices of the graph. The edges represent the flow of the preparation and cooking process. Each ingredient connects to the instruction in which it is used.
ResourceFunction["RecipeGraph"] supports Graph options provided as ResourceFunction["RecipeGraph"][,"GraphOptions"{opt1val1,}]. The default ImageSize is 600 points unless otherwise specified.
ResourceFunction["RecipeGraph"] supports the option LLMEvaluator and supports the same LLM models as LLMConfiguration.

Examples

Basic Examples (3) 

Create a graph for a simple baked beans recipe:

In[1]:=
ResourceFunction["RecipeGraph"]["Ingredients:
2 cans navy beans
1/2 cup barbecue sauce
1 tablespoon brown sugar
1/2 teaspoon dry mustard
Instructions:
Preheat oven to 350°F.
Pour the beans into a baking dish.
In a small bowl, mix the barbecue sauce, brown sugar and dry mustard until combined.
Pour the sauce mixture over the beans and stir gently.
Cover the baking dish with foil and bake for 30 minutes.
Serve warm and enjoy!"]
Out[1]=

Use the LLM to create the recipe as well:

In[2]:=
ResourceFunction["RecipeGraph"]@
 LLMSynthesize["Write a recipe for tomato basil soup"]
Out[2]=

Create a customized graph for baking blueberry scones:

In[3]:=
ResourceFunction["RecipeGraph"]["Ingredients:
2 cups all-purpose flour
1/3 cup granulated sugar
1 tablespoon baking powder
1/2 teaspoon salt
8 tablespoons unsalted cold butter, cut into cubes
1 cup fresh blueberries, rinsed
1/2 cup heavy cream
1 large egg
2 teaspoons vanilla
Instructions:
Preheat oven to 400°F.
In a large bowl, whisk together the flour, sugar, baking powder and salt.
Cut the cold butter cubes into the flour mixture until it resembles coarse crumbs, then fold in the blueberries.
In a separate bowl, whisk together the heavy cream, egg and vanilla. Pour the cream mixture into the dry ingredients, then mix gently until a dough starts to form. Do not overmix.
Place the dough on a floured surface and knead briefly, just until it comes together.
Press the dough into an 8-inch circle. Using a sharp knife or bench scraper sprayed with a neutral oil, cut the dough into 8 wedges and place them on a baking sheet lined with parchment paper. Leave space for them to expand.
Bake for 18-20 minutes, or until they are golden brown.
Serve warm or store in an airtight container for up to 3 days.", "GraphOptions" -> {EdgeStyle -> Dashed, VertexShapeFunction -> "Diamond", ImageSize -> 800}]
Out[3]=

Options (1) 

Specify the LLM model and use multiple Graph options to personalize this mustard vinaigrette recipe:

In[4]:=
ResourceFunction["RecipeGraph"]["
Ingredients:
1 Tbsp Dijon mustard
2 Tbsp sherry vinegar
1/3 cup extra virgin olive oil
1/8 tsp salt
Instructions:
Whisk together the Dijon mustard and vinegar.
Continue whisking and slowly add the olive oil, then the salt.
Taste and add more salt if needed.
Serve over salad or store in an airtight container in the refrigerator. Use within 1 week.", LLMEvaluator -> <|"Service" -> "OpenAI", "Name" -> "GPT-3.5"|>, "GraphOptions" -> {EdgeShapeFunction -> "UnfilledArrow", Background -> LightBlue, ImageSize -> 400, ImageMargins -> 10}]
Out[4]=

Neat Examples (1) 

Use ImageSynthesize to create an original image for the vertices of this apple crisp recipe graph:

In[5]:=
ImageSynthesize["basic drawing of 1 red apple"]
Out[5]=
In[6]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/c65158c0-1898-4568-b2b8-28ea9931eef7"]
Out[6]=

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.1.0 – 15 May 2024
  • 1.0.0 – 06 March 2024

Related Resources

Author Notes

Due to the color coding of the vertices and labels to distinguish ingredients and instructions, ResourceFunction["RecipeGraph"] does not support color changes using VertexStyle and VertexLabelStyle. The LLM may place the preheat oven instruction in the bottom-left of the graph, rather than the top-right, if it perceives there is not sufficient room due to the graph layout.

License Information