< all projects27 steps · easy · Rebuild
Build a model client
You will have built a model client with the standard library, one small function at a time: 3 that build the conversation, 5 that read a reply and finish one that was cut off, 5 that get JSON back and ask again when it is wrong, 4 that turn a stream into a reply, 3 that survive a busy API, 3 that count the cost, and 4 that put it all behind one client. Each step is a few lines with its own tests, and the earlier functions are provided to the later ones, so the pieces compose without you writing anything twice. The model is handed to you as an object with one method, `chat`, and is scripted while you build, so a rate limit or a cut-off reply arrives exactly when a step needs one. At work you would reach for the provider's SDK, a validation library and a retry library. This project is what those do for you. When every step has passed, the seven files assemble into one client and you can run it against a real model, with a receipt at the end.
Part 01 · 3 steps
Messages
Build the conversation you send.
Part 02 · 5 steps
Replies
Read what came back, and get the rest when it was cut off.
Part 03 · 5 steps
Structured output
Get JSON back, and ask again when it is wrong.
Part 04 · 4 steps
Streaming
Turn a stream of events into a reply.
Part 05 · 3 steps
Retries
Survive a busy API.
Part 06 · 3 steps
Cost
Know what every call cost.
Part 07 · 4 steps
The client
Put the pieces behind four functions.