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
- Several events in one chunk
- A line split between two chunks is joined
- Comment lines are ignored
- An unfinished event is not returned
- 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.