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
- Unknown models fall back to small and big values are clamped
- Allowed models and defaults are kept
- An empty body gets the defaults
max_tokensis never below 1- 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.