Lesson 4 — Calling a (fake) model
One turn of a chat
Calling a model means: send the message list, get back one new message with "role": "assistant". Our fake_llm(messages) returns exactly that shape:
answer = model(chat_log) # {"role": "assistant", "content": "..."}
chat_log.append(answer) # keep it, so the next call sees it
A turn is one user message plus the model's reply. The list that grows turn after turn is the history.
Why it matters: with a real provider, this one line becomes an API call such as client.messages.create(...) (Anthropic) or client.chat.completions.create(...) (OpenAI). The rest of your function — append the question, call, append the reply — does not change.
Watch out: if you forget to append the reply, the model "forgets" what it said and the conversation stops making sense.
Finish chat(): call fake_llm(history), append the reply to history, and return the reply's text.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.