Command Palette

Search for a command to run...

Hectal
Phase 5: Streaming and UX
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

  1. A normal stream is complete
  2. Ending without a finish reason is cut off
  3. A [DONE] without a finish reason is cut off
  4. A connection error keeps the text read so far
  5. 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.