Record the failure, then re-raise
ProviderError and a fake model are given. Write observed_call(model, prompt, records) that calls model.complete(prompt), which returns a dict with tokens_in, tokens_out and latency_ms, or raises ProviderError.
Append exactly one record to records for every call: {"status": "ok" or "error", "tokens_in": ..., "tokens_out": ..., "latency_ms": ...}. On success return the reply. On a ProviderError the record has the status error, tokens_out 0, tokens_in equal to (len(prompt) + 3) // 4 and latency_ms taken from the exception's latency_ms attribute, and the error must be raised again.
What Check tests
- A successful call returns the reply and records it
- A failed call is still recorded
- The error is raised again to the caller
- Exactly one record per call, in order
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Output
Press Run to see what your program prints.