cohere-python
cohere-python copied to clipboard
🌿Fern Support: Fix for SSE Parsing Bug
Slack thread: https://buildwithfern.slack.com/archives/C05KKD1P8BG/p1751913443809909
- Fixes dropped threads due to bad json handling by
httpx.Response.iter_lines()- useshttpx.Response.iter_bytes()instead - Added handling for empty events and
[DONE]events - Improved error logging when parsing of SSE events fail
This PR introduces a forked and fixed version of httpx_sse to handle multi-line SSE data fields properly. It consolidates all httpx_sse functionality into a single file.
- Added a new module
http_sse.pythat includes classes and functions for handling Server-Sent Events (SSE). - Replaced the use of
httpx_ssewith the newEventSourceclass fromhttp_sseinraw_client.py. - Updated the event handling logic in
raw_client.pyto skip empty events and handle the[DONE]token from OpenAI-style APIs. - Added error handling for JSON decoding and parsing errors in
raw_client.py.