Chat Loop
💬 Models don't remember anything on their own. To hold a conversation, your bot keeps a message history: a list of every message so far, sent in full each time.
messages = []
messages.append({"role": "user", "content": "Hi!"})
reply = pip.chat(messages)
messages.append({"role": "assistant", "content": reply})Each message is a dict with a role (who said it) and content (what they said). pip.chat() reads the whole list and answers the last user message. That's memory, the simple way. Finish this one for your second badge: First Contact.
Instructions
- Make an empty list:
messages = [] - Loop over
talk. Each time, add{"role": "user", "content": text}tomessages. - In the loop, store
pip.chat(messages)inreply, print it, and add it as{"role": "assistant", "content": reply}. - At the end,
messagesholds 6 messages and Pip saysYour name is Sam.
💡 Hint
for text in talk: append the user message, then reply = pip.chat(messages), print(reply), then append the assistant message. All 4 lines indented inside the loop.