Start learning free

LESSON 2 OF 129 · AI ENGINEERING: CALLING A MODEL

System and User Messages in Python

Practice

A model knows only what its training taught it and what you send it now. When a customer of the Corner Shop types "When are you open?", the model gets four words. It has no idea whose customer this is.

The system prompt: the customer shouldn't have to explain where they are. That is your program's job, and it has its own place: the system prompt, text from you, the developer, that tells the model who it is, how to behave and the facts it needs. A long one reads better as short pieces: Python joins the strings inside the parentheses into one string.

SYSTEM = (
    "You are the City Library's assistant. "
    "The library closes at 18:00. "
)

The system prompt is not one of the messages. It travels next to them, in its own argument of client.messages.create, called system. The messages list stays the same: the customer asks the same question.

This lesson's program asks the question twice and must print:

Without a system prompt: I'm an AI model, so I don't have opening hours. Which place do you mean?
With a system prompt: The Corner Shop is open from 8:00 to 20:00, every day. See you soon!

Your task: client, MODEL and messages, with the customer's question, are ready. Send the question as it is and print the answer. Then write a system prompt SYSTEM that says the model is the Corner Shop's assistant, send the same question with it and print the new answer. Last, add the shop's hours to the system prompt.


Assignment
Follow the Coding Tutorial to ask the same question without and with a system prompt and print both answers.


Hint
Don't put the system prompt in messages: pass it by name, system=SYSTEM, next to the other arguments. Each piece of SYSTEM ends with a space, so the joined sentences don't stick together.


STEP 1 OF 7
    Ctrl + Enter to check

    Ai System Prompt in Python

    Keep going with Python1,600+ step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free