You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
…#498
This commit updates the SSE parser to handle cases where there is an optional space after the "data:" prefix. Described in detail here - openai#498
To address this, I modified the parser code to use the `startswith` method and then strip any leading or trailing whitespaces from the line. This ensures that the parser can handle both cases where there is a space after "data:" and where there isn't. The modified code now correctly decodes the line as UTF-8 and returns the parsed data.
This change improves compatibility with different SSE implementations and ensures that the parser functions correctly in various scenarios. It provides a more flexible solution that aligns with the SSE specification and accommodates libraries like springframework that omit the space after "data:".
Fixesopenai#498
Describe the bug
In openai-python the SSE parser always check the additional space after "data:"
openai-python/openai/api_requestor.py
Line 106 in 041bf5a
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
The text was updated successfully, but these errors were encountered: