Jonathan 偉良 Routley

GPT3 Recipe Writer

I’ve seen ChatGPT everywhere at the moment so wanted to play around with the OpenAI API and see if I could come up with something useful (to me). I sometimes write up recipes for myself or friends, but have stopped largely due to laziness in making them properly readable. I wrote some code to flesh out the skeleton of a recipe into a fully-formed, readable recipe, and intend to use this regularly.

Full code on GitHub

Code

This task is very simple to implement and largely follows the API docs:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def complete_recipe(instruction):
    prompt = """ 
    Turn the following lines from a recipe into a complete sentence, and give the output as a numbered list in markdown format: {}
    """.format(instruction)

    response = openai.Completion.create(
        model="text-davinci-003",
        prompt=prompt,
        temperature=0.4,
        max_tokens=1000
    )

    return response.choices[0].text

The temperature parameter defines the ‘riskiness’ of the model. This app should favour lower temperatures (less risky) as we want to get repeatable results and are not looking for anything too creative.

Running this code with the instruction input as:

dice onion carrot
mince garlic ginger
heat wok medium-high add oil when shimmering add onion carrot
stir fry until soft, add garlic and ginger
when fragrant add rice wok stir fry 2-3 mins break clumps
make space in middle, crack eggs, salt. Scramble when set break into chunks and mix in rice
add soy sauce, sesame oil
enjoy

We get this output:

1. Dice the onion and carrot.
2. Mince the garlic and ginger.
3. Heat a wok to medium-high, add oil when shimmering, and add the onion and carrot.
4. Stir fry until soft, then add the garlic and ginger.
5. When fragrant, add the rice to the wok and stir fry for 2-3 minutes, breaking up any clumps.
6. Make space in the middle, crack the eggs and add salt. Scramble the eggs until set, then break them into chunks and mix them into the rice.
7. Add soy sauce and sesame oil.
8. Enjoy!

This works pretty much exactly as intended. Varying the temperature between 0.0 and 1.0 for this example yields very similar results (save some punctuation changes).



Extra

After writing the code for this post I asked ChatGPT how it would do the same thing. The results are below and are totally not terrifying.

ChatGPT 1

ChatGPT 2

ChatGPT 3

ChatGPT 4