Lesson ยท 12 min
Roles and the system message
Three roles
Each message has a role. There are three roles.
| Role | Who writes it | What it is for |
|---|---|---|
system |
You, the developer. | Instructions that stay the same for every call: the job, the rules, and the form of the answer. |
user |
The person who uses your program, or your program. | The text for this call: a question, or the data to work on. |
assistant |
The model. | An answer that the model gave before. Lesson 5 uses it. |
A system message is always the first message of the list.
RULES = "Summarize the text in 8 words."
comment = "The dock at Town Hall was full."
messages = [
{"role": "system", "content": RULES},
{"role": "user", "content": comment},
]
Why two messages
You can put the instructions and the data in one user message, as you did in lesson 1. Two messages are better for a program.
- The instructions are in one place. You write them one time, and each call uses them.
- The data stays data. Your program puts the comment of a rider in the user message, and it does not mix the comment with your instructions.
- You can change the instructions and test them without a change to the rest of the program.
Say what you want
A model does what the messages say, and nothing tells it what you have in your head. If you send only a comment, the model does not know that you want a label. If you ask for a label but not for the form, you get a full sentence. A program cannot work with a sentence as well as with one word.
Compare these instructions. The answers are those of the simulated model of this course.
| Instructions | Answer |
|---|---|
Classify the comment. |
I think this comment is a complaint. It has the word "full". |
Classify the comment as one of: praise, complaint, question, other. Answer with one word. |
complaint |
The second form names the allowed labels and the form of the answer. Your code can compare the answer with a label directly.
Your turn
main.py has four comments of riders. Do the tasks in order.
Tasks
4 to do
Task 1, not checked yet. Call the model with one user message. Its content is the first comment, and nothing else. Store the text of the answer in a variable
plain.Task 2, not checked yet. The model did not know what to do with the comment. Make a variable
SYSTEMwith these instructions:Classify the comment as one of: praise, complaint, question, other. Answer with one word.Task 3, not checked yet. Write a function
classify(comment). It sends two messages: a message with the rolesystemand the contentSYSTEM, and then a message with the roleuserand the comment. It returns the text of the answer.Task 4, not checked yet. Make a list
labelswith the label of each comment incomments. Use your function.
Task 1 of 4
Call the model with one user message. Its content is the first comment, and nothing else. Store the text of the answer in a variable plain.