Skip to content

< CurriculumModel APIs · 2 of 46 ·61 · Level 01, LLM APIs

Carry the Conversation Yourself

easy · debug · LLM Fundamentals

A user tells your chatbot their name, and one message later the bot has no idea what it is. A model API is stateless: if the model is to know what was said two turns ago, you have to send it again, every time.

Fix Chat so that:

  1. Every request carries the whole conversation so far, oldest first, ending with the new user message.
  2. The model's reply is recorded as a message with role "assistant", so the next request includes it.
  3. The system prompt travels in the system argument on every call. It is not part of any message.
  4. A failed call leaves no trace. If the request raises, the conversation must be exactly what it was before send was called, and the error must still reach the caller.

chat.messages is the history: a list of {"role": ..., "content": ...} dicts, roles alternating user, assistant, user, assistant. send(text) returns the reply's text.

The model is scripted. The tests read what your class sent it.