mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
fix(proxy): serialize non-dict mappings in late SSE frames
orjson rejects mappingproxy. Copy the mapping to a dict before writing the data frame, and let ruff format the helper.
This commit is contained in:
parent
01a5fba937
commit
0cc4d66624
1 changed files with 4 additions and 5 deletions
|
|
@ -1167,12 +1167,10 @@ async def _aclose_late_response(produced: Response) -> None:
|
|||
def _late_response_body(produced: object) -> bytes:
|
||||
"""Bytes for one SSE data frame.
|
||||
|
||||
A late payload may be a dict, raw bytes, or a Response whose ``body`` is either.
|
||||
A late payload may be a mapping, raw bytes or text, or a Response whose ``body`` is one of those.
|
||||
"""
|
||||
payload: Final = (
|
||||
produced
|
||||
if isinstance(produced, (bytes, bytearray, Mapping))
|
||||
else getattr(produced, "body", produced)
|
||||
produced if isinstance(produced, (bytes, bytearray, Mapping)) else getattr(produced, "body", produced)
|
||||
)
|
||||
if isinstance(payload, (bytes, bytearray)):
|
||||
raw: Final = bytes(payload)
|
||||
|
|
@ -1181,7 +1179,8 @@ def _late_response_body(produced: object) -> bytes:
|
|||
text: Final = payload.encode()
|
||||
return text or b"{}"
|
||||
if isinstance(payload, Mapping):
|
||||
return orjson.dumps(payload)
|
||||
# orjson rejects mappingproxy and other non-dict mappings.
|
||||
return orjson.dumps(dict(payload))
|
||||
return b"{}"
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue