cohere-python icon indicating copy to clipboard operation
cohere-python copied to clipboard

🌿Fern Support: Fix for SSE Parsing Bug

Open fern-support opened this issue 3 months ago • 0 comments

Slack thread: https://buildwithfern.slack.com/archives/C05KKD1P8BG/p1751913443809909

  • Fixes dropped threads due to bad json handling by httpx.Response.iter_lines() - uses httpx.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.py that includes classes and functions for handling Server-Sent Events (SSE).
  • Replaced the use of httpx_sse with the new EventSource class from http_sse in raw_client.py.
  • Updated the event handling logic in raw_client.py to 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.

fern-support avatar Sep 27 '25 18:09 fern-support