A model such as Claude is a program that reads text and writes text back. Your code talks to it the way it talked to the supplier: it sends a request and an answer comes back. The anthropic library does the sending, through client.
Messages: what you send is a prompt, plain words that say what you want. It travels inside a message: a dictionary with a "role", who is speaking, and a "content", what they say. Your side of the chat has the role "user".
{"role": "user", "content": "Suggest a name for a tea shop."}
The call client.messages.create takes three things by name: the model that should answer, max_tokens, the most it may write (a token is a piece of a word, about four letters), and messages, a list of messages. What comes back is a message too. Its role is assistant, and its content is a list of blocks: the first block's .text is the answer as a string.
This lesson's program must print:
Role: assistant Text: A sky-blue ceramic mug that keeps your coffee warm and your mornings bright.
Your task: client and MODEL are ready. Ask the model to write a one-line description for a blue ceramic mug: put the prompt in question, wrap it in a messages list with one user message, send it with max_tokens=200, and print the reply's role and its text. (In these lessons a course model stands in for the real one, so everyone gets the same answer.)
Assignment
Follow the Coding Tutorial to send your first message to a model and print the role and the text of its reply.
Hint
The reply's content is a list of blocks, not a string. The text you want is in the first block, at index 0, in its .text.
Free plan: 30 tutor messages. PRO is unlimited.
