Exercise 6 of 10 · 0 passed
The Provider Protocol Pattern
When your code is tightly coupled to one LLM provider, swapping is painful and testing requires live API calls. Python's Protocol fixes both.
class LLMProvider(Protocol):
def complete(self, messages: list[dict]) -> str: ...
Any class with a matching complete method satisfies this — no inheritance needed. Your service only sees the Protocol, never the concrete class.
Why care? Swap providers by changing one line at the call site. Test without hitting any API. The cohort uses this same pattern to support OpenAI and Groq side by side — once you've got the Protocol, adding a third provider is a 30-line file.
Task
The LLMProvider Protocol is defined. Implement:
ClaudeProvider— wraps the Anthropic SDKMockProvider— returns a fixed string and records every call inself.calls
Click "Run tests". First time loads Python in your browser (~5s). After that, runs are instant on this page and ~1s on the others.
Loading tests…
Pass the tests to reveal the reference solution.
The point of the exercise is the struggle, not the answer. Once your tests are green, the reference solution unlocks here so you can compare patterns.
Loading solution…
That's the warm-up.
You ran ten exercises against a mocked SDK. The cohort builds the real thing: an AI agent shipped to production with 150+ passing tests, Telegram bot, FastAPI, Streamlit, Docker. Six weeks. Every PR reviewed.