Command Palette

Search for a command to run...

Hectal
Phase 2: Calling a Model
LLM Engineering · Exercise 6 of 6 Previous
Intermediate

Wrap any model in a recorder

FakeModel is given. Write a class Recorder whose constructor takes an inner model. Its complete(messages, max_tokens=100) calls inner.complete(messages, max_tokens) and returns the reply unchanged.

It also appends a dictionary {"messages": len(messages), "max_tokens": max_tokens, "text": reply["text"]} to a list attribute calls.

What Check tests

  1. The reply is passed through unchanged
  2. Each call is recorded with the message count, limit and text
  3. max_tokens is forwarded to the wrapped model
  4. Recorders can be stacked

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.