Skip to content

Fix Stream parser expects additional space after colon "data:"#502

Closed
AshiishKarhade wants to merge 1 commit intoopenai:mainfrom
AshiishKarhade:sse-stream-parser-fix
Closed

Fix Stream parser expects additional space after colon "data:"#502
AshiishKarhade wants to merge 1 commit intoopenai:mainfrom
AshiishKarhade:sse-stream-parser-fix

Conversation

@AshiishKarhade
Copy link
Copy Markdown

This commit updates the SSE parser to handle cases where there is an optional space after the "data:" prefix. Described in detail here - #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:".

Fixes #498

…#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:".

Fixes openai#498
@AshiishKarhade AshiishKarhade changed the title Fix Stream parser expects additional space after colon "data:" #498 Fix Stream parser expects additional space after colon "data:" Jun 25, 2023
@michaelfeil
Copy link
Copy Markdown
Contributor

#559 was merged, this can be closed.

safa0 pushed a commit to safa0/openai-agents-python that referenced this pull request Apr 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants