Command Palette

Search for a command to run...

Hectal
Phase 2: Calling a Model
LLM Engineering · Exercise 3 of 6 PreviousNext
Beginner

Read any reply without crashing

Write summarise_reply(text) that parses a chat-completions reply and returns a dictionary with keys answer, finish and tokens.

answer is choices[0].message.content, or "" if it is missing, null or there are no choices. finish is finish_reason, or "unknown" if missing. tokens is usage.prompt_tokens + usage.completion_tokens, or None if there is no usage.

What Check tests

  1. A normal reply
  2. Null content and no usage (a tool call)
  3. Empty choices
  4. A null message (a filtered reply)
  5. A missing finish_reason gives "unknown"

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.