LLM Engineering · Exercise 5 of 5 Previous
Intermediate
Is the stream complete?
Write stream_status(events). events is an iterable of data strings (JSON chunks, maybe "[DONE]"). Iterating it may raise ConnectionError partway.
Join the delta.content pieces. Return ("complete", text) only when some chunk had a non-null finish_reason. Return ("cut off", text) when the connection error is raised, or the events end (or [DONE] arrives) without any finish reason. text is what was read before the break.
What Check tests
- A normal stream is complete
- Ending without a finish reason is cut off
- A [DONE] without a finish reason is cut off
- A connection error keeps the text read so far
- A finish reason of length still counts as a finish
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.