1. Your first model call
Every AI app, agent and framework sits on top of one thing: an HTTP request to a model. In this module you send that request yourself.
The chat completions API
Section titled “The chat completions API”Most model servers speak the same protocol, first made popular by OpenAI and now supported by Ollama, LM Studio, vLLM, llama.cpp and nearly every cloud provider. You POST a list of messages to /chat/completions and get the next message back.
{ "model": "qwen3:4b-instruct", "messages": [ {"role": "system", "content": "You are a friendly conference assistant."}, {"role": "user", "content": "What's a good first AI talk to attend?"} ], "temperature": 0.7}{ "choices": [ {"message": {"role": "assistant", "content": "Try a beginner keynote..."}} ]}There are three roles:
- system: instructions from you, the developer. The user doesn’t see them.
- user: what the person typed.
- assistant: what the model replied.
Exercise: make the call
Section titled “Exercise: make the call”Open code/01-first-conversation/starter/chat.py. The chat loop is written for you. Your job is the ask() function and two lines in the loop.
TODO 1: send the request with httpx and return the reply text.
def ask(messages): response = httpx.post( f"{config.BASE_URL}/chat/completions", headers={"Authorization": f"Bearer {config.API_KEY}"}, json={ "model": config.MODEL, "messages": messages, "temperature": 0.7, }, timeout=config.TIMEOUT, ) response.raise_for_status() return response.json()["choices"][0]["message"]["content"]config reads your .env file, so the same code works with any provider.
Run it:
python 01-first-conversation/starter/chat.pyAsk it something. Then ask a follow-up like “Can you say that more briefly?” What happens?
Models have no memory
Section titled “Models have no memory”The model forgot what it just said. That’s not a bug. Models are stateless. Every request is a fresh start, and the only memory is the list of messages you send. Chat apps feel like they remember because they resend the whole conversation every time.
TODO 2 and 3: append the user’s message before calling ask(), and append the model’s reply after.
messages.append({"role": "user", "content": user_input}) reply = ask(messages) messages.append({"role": "assistant", "content": reply})Run it again and try the follow-up. Now it remembers.
Try this
Section titled “Try this”- Change the system prompt to make the assistant answer only in pirate speak. Then ask it to stop. Who wins, the system prompt or the user?
- Set
temperatureto0and ask the same question three times. Then try1.5. What changes? - Ask it which sessions are on Day 2 of the Lumen AI Summit. It will probably make some up. Hold that thought.
Checkpoint. You can call a model with plain HTTP and keep a conversation going. You also saw its biggest weakness: it confidently answers questions it has no data for.
Stuck? Run the finished version: python 01-first-conversation/solution/chat.py