Command Palette

Search for a command to run...

Hectal
Phase 12: Building a Production LLM Service
LLM Engineering · Exercise 1 of 6Next
Intermediate

Clean an incoming chat request

Write clean_request(body) that takes a dictionary and returns a new dictionary with the keys model and max_tokens.

model must be one of ALLOWED_MODELS; use "small" when it is missing or not allowed. max_tokens defaults to 256 when missing, and is never below 1 or above MAX_TOKENS_CAP. Ignore every other key in body.

What Check tests

  1. Unknown models fall back to small and big values are clamped
  2. Allowed models and defaults are kept
  3. An empty body gets the defaults
  4. max_tokens is never below 1
  5. The input dictionary is not changed

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.