Command Palette

Search for a command to run...

Hectal
Phase 5: Streaming and UX
LLM Engineering · Exercise 1 of 5Next
Intermediate

Write the SSE parser

Write sse_events(chunks). chunks is a list of text pieces cut anywhere from an SSE stream. Return the list of data strings of every complete event, in order.

An event ends at a blank line (\n\n). Its data is the text after data: on each data: line (remove one space after the colon; join several data lines with \n). Ignore lines that start with :. Text after the last blank line is unfinished and must not be returned.

What Check tests

  1. Several events in one chunk
  2. A line split between two chunks is joined
  3. Comment lines are ignored
  4. An unfinished event is not returned
  5. One character at a time gives the same events

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.