Prompting

Ethan Mollick’s Getting started with AI: Good enough prompting

Treat AI like an infinitely patient new coworker who forgets everything you tell them each new conversation, one that comes highly recommended but whose actual abilities are not that clear. Two parts of this are analogous to working with humans (being new on the job and being a coworker) and two of them are very alien (forgetting everything and being infinitely patient). We should start with where AIs are closest to humans, because that is the key to good-enough prompting.

A conversation

curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-4.1",
    "messages": [
      {"role": "system", "content": "You are a terse assistant."},
      {"role": "user", "content": "What is the capital of the moon?"},
      {"role": "assistant", "content": "The moon does not have a capital. It is not inhabited or governed."},
      {"role": "user", "content": "Are you sure?"}
    ]
}'
  • Model: model used
  • System prompt: behind-the-scenes instructions and information for the model
  • User prompt: a question or statement for the model to respond to

English

“The hottest new programming language is English” Andrej Karpathy

https://x.com/karpathy/status/1617979122625712128?lang=en

System Prompt

Python

from chatlas import ChatOpenAI

chat = ChatOpenAI()
chat.system_prompt = "I want you to act like Yoda."
chat.chat("I need your help.")

R

library(ellmer)

chat <- chat_anthropic()
chat$set_system_prompt("I want you to act like Yoda")
chat$chat("I need your help.")
02:00

Prompt templates

Python

prompt.md

I want you to act like {{ role }}

Python

from chatlas import ChatOpenAI, interpolate_file

chat = ChatOpenAI()
chat.system_prompt = interpolate_file(
  "prompt.md",
  variables={"role": "Yoda"},
)
chat.system_prompt

R

library(ellmer)

chat <- chat_anthropic()
chat$set_system_prompt(
  interpolate_file("prompt.md", role = "Yoda")
)
chat$get_system_prompt()
02:00

Guides on prompt writing

Writing a good prompt: RODES

  • Role: Set the scene
  • Objective: Define a purpose
  • Detail: Influence behaviour, provide missing information, follow up information
  • Example: Use specific examples, outline tasks,
  • Style:

Example: Instagram cooking reel (Role)

You are a useful and understanding chef trying to help me create a recipe book.

Example: Instagram cooking reel (Objective)

I will be giving you cooking instructions and I need you you format the content into a recipe card. The recipe card will provide a shopping list, list of ingredients, and then a set of instructions on how to cook the ingredients.

Example: Instagram cooking reel (Detail)

Please provide all units and measurements in both metric and imperial measurements. If you are unsure about a measurement or instruction, I would rather you tell me to look into the original source, than try to make it up.

Sort the shopping list by grocery store aisle. Provide the output in the following order: shopping list, ingredient list, cooking instructions.

The text may be in different languages. Translate any non English text into English and return all the results in English.

Below are the video and text instructions.

Example: Instagram cooking reel (Example)

None.

Example: Instagram cooking reel (Style)

Keep the output text around 80 characters per line.

Example Instagram cooking reel (Output)

Crispy Rice Salmon Cucumber Salad with Creamy Asian Dressing

────────────────────────────────────────────────────────────────────────────────
Shopping List

Produce Aisle:

 • 5 Persian cucumbers (or 1 large English cucumber)
 • 1 avocado
 • 1 bunch green onions (about 3/4 cup)

Frozen Aisle:

 • 1 cup shelled edamame

Meat & Seafood:

 • 8 oz (227 g) salmon

Grains & Rice:

 • 2 cups cooked jasmine rice

Condiments:

 • Soy sauce
 • Chili crisp/crunch
 • Sesame oil
 • Olive oil
 • Toasted sesame oil
 • Rice vinegar
 • Honey

Spices:

 • Garlic powder
 • Ground ginger
 • Kosher salt
 • Black pepper

────────────────────────────────────────────────────────────────────────────────
Ingredients

Crispy Rice:

 • 2 cups cooked jasmine rice (450 g), cooled
 • 2 tsp soy sauce (10 ml)
 • 2 tbsp chili crisp/crunch (30 g)
 • 1 tbsp sesame oil (15 ml)

Salmon:

 • 8 oz (227 g) salmon
 • Pinch of garlic powder
 • Salt and pepper to taste

Salad:

 • 5 Persian cucumbers, thinly sliced (or 1 large English cucumber)
 • 1 cup shelled edamame (150 g)
 • 1 bunch green onions, thinly sliced (approximately 3/4 cup)
 • 1 avocado, diced

Creamy Asian Dressing:

 • 1/4 cup olive oil (60 ml)
 • 1/4 cup toasted sesame oil (60 ml)
 • 3 tbsp soy sauce (45 ml) or coconut aminos
 • 3 tbsp rice vinegar (45 ml)
 • 2 tbsp honey (30 g)
 • 1 1/2 tsp ground ginger (7 g)
 • 1/2 tsp kosher salt (3 g)

────────────────────────────────────────────────────────────────────────────────
Cooking Instructions

  1 Preheat the oven to 400°F (200°C). Line a baking sheet with parchment paper.
  2 Spread the cooked and cooled jasmine rice on the baking sheet.
  3 Toss the rice with soy sauce, chili crisp, and sesame oil. Bake for 30-35
    minutes, stirring halfway to ensure it doesn’t burn.
  4 While the rice bakes, season the salmon with garlic powder, salt, and
    pepper. Place on another baking sheet.
  5 Add the salmon to the oven with the rice and bake for 13-14 minutes, or
    until desired doneness.
  6 Once done, remove the crispy rice from the oven and set it aside.
  7 Shred the salmon into smaller pieces and set aside.
  8 In a large bowl, combine the sliced cucumbers, shelled edamame, thinly
    sliced green onions, and diced avocado.
  9 Top the salad with the shredded salmon and crispy rice.
 10 For the dressing, whisk together olive oil, toasted sesame oil, soy sauce,
    rice vinegar, honey, ground ginger, and kosher salt.
 11 Taste the dressing and adjust seasonings as needed. Pour it over the salad
    and toss everything gently to combine.
 12 Enjoy your delicious Crispy Rice Salmon Cucumber Salad!

────────────────────────────────────────────────────────────────────────────────
Feel free to follow these steps for a refreshing and textured salad experience!

Demo: Instagram cooking reel

https://github.com/chendaniely/ai-hackathon-2024

You Try

  • Change your system prompt
  • Change your model

See the Models page for some example models

05:00