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
- A normal reply
- Null content and no usage (a tool call)
- Empty choices
- A null message (a filtered reply)
- 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.