Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 0.7 — Playbook: Your First LLM Feature
LLM Engineering · Example 1 of 2

Recipe: a fake-first model client

The feature is tested against cut-off and empty replies before any real model is involved.

Two recipes to start every LLM feature: a fake model behind the same interface as the real one, so the feature is testable from day one, and a meter that counts tokens, estimates cost and refuses calls over budget. Plus the checklist to run before you ship.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Extend FakeModel so a scripted reply can be an exception (for example a RateLimitError instance) that complete raises instead of returning, and test that summarise lets it propagate.

02

Add a report() method to the meter that returns "calls=N tokens_in=N tokens_out=N cost=$X" with the cost to 6 decimals.

Explain it without notes

01

Why build an LLM feature against a fake model first?

02

Why does the budget guard check the worst case before the call instead of the actual cost after it?

Recipe: a fake-first model client
Sign in to run this example in your browser.

Expected output

normal reply   -> Rain is expected all week in Pune.
cut-off reply  -> ERROR: summary was cut off (raise max_tokens or ask for less)
empty reply    -> ERROR: empty summary
requests recorded: 3, system prompt: Summarise the user's text in one sentence.