Skip to content

SSE Stream parser expects additional space after colon "data:" #498

Closed
@rick-li

Description

@rick-li

Describe the bug

In openai-python the SSE parser always check the additional space after "data:"

if line.startswith(b"data: "):

But according to the SSE spec "data: " is identical to "data:"
https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events
`The following stream fires two identical events:
data:test

data: test
This is because the space after the colon is ignored if present.`

The use case is some organizations might proxy the response for additional control but not all library put a whitespace after the colon ex. springframework https://github.com/spring-projects/spring-framework/blob/f06cf21341a35f863b327e0bfe2305111f69c468/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageWriter.java#L146
if (data != null) { sb.append("data:"); }

To Reproduce

Proxy OpenAI API with spring framework

Code snippets

No response

OS

All

Python version

All

Library version

All

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions