Build Your First AI Agent / Chapter 2: Talk to the Model
Feedback
Quest

08. Fortune Teller

Most prompts are built from pieces. An f-string (an f right before the quotes) lets you drop variables into text with curly brackets.

food = "tacos"
msg = f"I could eat {food} every day."
print(msg)
I could eat tacos every day.

That's a prompt template: the same sentence, filled in with different words each time.

Instructions

  1. Make two text variables: name and thing.
  2. Build prompt with an f-string: f"Tell a fortune for {name} who loves {thing}."
  3. Print pip.ask(prompt).
Hint

Put an f right before the opening quote, and the variable names inside { }. Keep the full stop at the end.

Solution
import pip
name = "Sam"
thing = "pizza"
prompt = f"Tell a fortune for {name} who loves {thing}."
print(pip.ask(prompt))
Still stuck?

Press "Talk it out" at the top. Our Discord opens soon; until then email us and paste your code.

Chapter quests
  1. Chapter 1: Hello, Bot
  2. Chapter 2: Talk to the Model
    1. First Words 10 XP
    2. Who Are You? 10 XP
    3. Fortune Teller 10 XP
    4. Tidy Reply 10 XP
    5. Chat Loop 15 XP
  3. Chapter 3: Tools CLUB
  4. Chapter 4: Memory CLUB
  5. Chapter 5: Loops and Plans CLUB
  6. Chapter 6: Party of Agents CLUB
bot.py
Terminal
Chapter 2: Talk to the ModelQuest 3 / 510 XPBackNext

Talk it out

  1. What did you expect your bot to do?
  2. What did it actually print? Read the terminal, line by line.
  3. What's different? Spelling, capitals, spaces and full stops all count.
  4. Is there an error? It tells you the line number. Look there first.
  5. Read the instructions again, one at a time. Each one is checked on its own.

Badge unlocked:

Your bot got a new part. Chapter complete!

Make your bot

Pick a name and a colour. You can change them later.