Start learning free

LESSON 23 OF 129 · AI ENGINEERING: PROMPTS THAT HOLD UP

Version Your Prompts

Practice

A prompt is part of your program: change one word and every answer can change. So treat it like code you may need to undo. Give each wording a version name, keep them all in one dictionary, and let one setting say which one is live.

Here is the idea on something else, the subject line of the shop's emails:

SUBJECTS = {
    "v1": "Your order",
    "v2": "Good news: your order is on its way",
}
SUBJECT_VERSION = "v2"

print(SUBJECTS[SUBJECT_VERSION])
# Good news: your order is on its way

Two habits make this work. A version that has been used never changes: a new wording gets a new name. And every answer is printed with the version that made it, so a bad answer can be traced to its prompt and rolled back by changing one line.

In this lesson the Corner Shop's assistant has two prompts: v1, and a tighter v2 that asks for one short sentence. With v2 live, your program asks two questions and must print:

[v2] Do you ship abroad? -> Yes, we ship abroad.
[v2] Can I pay in cash? -> No, we take cards only.

The check then sets the version back to "v1" and asks the first question again. The long v1 answer comes back, and it names the EU and the UK, which the short v2 answer left out.

Your task: client, MODEL, FACTS, questions and most of the function ask are already there. Make the dictionary PROMPTS with the entries "v1" and "v2", and the setting PROMPT_VERSION with the value "v2". Inside ask, set system to the entry the setting points to. Then loop over questions and print each answer with its version in square brackets.


Assignment
Follow the Coding Tutorial to store two prompt versions, pick one with a setting, and print every answer with the version that made it.


Hint
Both entries start with FACTS +, then the wording: "Answer the customer." for v1 and "Answer the customer in one short sentence." for v2. Read a dictionary entry by its key with square brackets. Build the tag with + so the brackets touch the version.


STEP 1 OF 8
    Ctrl + Enter to check