Function Repository Resource:

RecipeGraph

Source Notebook

Create a graph of the ingredients and instructions for a recipe

Contributed by: Gay Wilson, Tommy Peters and Jeff Bryant

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 with the following changes: 1) The default ImageSize is 600 points. 2) The default ImagePadding is 30 points. 3) ResourceFunction["RecipeGraph"] does not support color changes using VertexLabelStyle.
ResourceFunction["RecipeGraph"] supports the option LLMEvaluator and supports the same LLM models as LLMConfiguration.
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.

Examples

Basic Examples (2) 

Create a graph for a simple baked beans recipe:

In[1]:=
ResourceFunction["RecipeGraph"]["Ingredients:
2 cans navy beans
1/2 cup barbecue sauce
1 Tbsp brown sugar
1/2 tsp 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[2]=

Use the LLM to create the recipe as well:

In[3]:=
ResourceFunction["RecipeGraph"]@
 LLMSynthesize[
  "Write a recipe for tomato basil soup using whole canned tomatoes. Use abbreviations Tbsp and tsp."]
Out[3]=

Create a customized graph for baking blueberry scones:

In[4]:=
ResourceFunction["RecipeGraph"]["Ingredients:
2 cups all-purpose flour
1/3 cup granulated sugar
1 Tbsp baking powder
1/2 tsp salt
8 Tbsp unsalted cold butter, cut into cubes
1 cup fresh blueberries, rinsed
1/2 cup heavy cream
1 large egg
2 tsp 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.", EdgeStyle -> Dashed, VertexStyle -> Orange, ImageSize -> 800]
Out[4]=

Options (1) 

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

In[5]:=
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"|>, EdgeShapeFunction -> "UnfilledArrow", Background -> LightBlue, ImageSize -> 400, PlotLabel -> Style["Mustard Vinaigrette", Bold]]
Out[5]=

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