Messages, roles, and the response — the call AI ships every time — step 9 of 9
Checkpoint
One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.
Final drill. Build a multi-turn chat helper. Write chat(history, new_message)
that:
- Appends a new user turn
{"role": "user", "content": new_message}tohistory. - Calls
fake_create(history)to simulate the model. - Appends the assistant reply to
historyas{"role": "assistant", "content": <reply text>}. - Returns the updated
history.
Then the script will run two turns and print every turn's role and content. Expected output:
user: hi
assistant: hello
user: who are you?
assistant: an assistant.
⌘↵ runs the editor.read, then continue.
Checkpoint
One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.
Final drill. Build a multi-turn chat helper. Write chat(history, new_message)
that:
- Appends a new user turn
{"role": "user", "content": new_message}tohistory. - Calls
fake_create(history)to simulate the model. - Appends the assistant reply to
historyas{"role": "assistant", "content": <reply text>}. - Returns the updated
history.
Then the script will run two turns and print every turn's role and content. Expected output:
user: hi
assistant: hello
user: who are you?
assistant: an assistant.
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.