Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Use non-strict JSON loading in Anthropic chunk responses #1130

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/codegate/muxing/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ def _format_antropic(self, chunk: str) -> str:
"""
cleaned_chunk = chunk.split("data:")[1].strip()
try:
chunk_dict = json.loads(cleaned_chunk)
# Use `strict=False` to allow the JSON payload to contain
# newlines, tabs and other valid characters that might
# come from Anthropic returning code.
chunk_dict = json.loads(cleaned_chunk, strict=False)
except Exception as e:
logger.warning(f"Error parsing Anthropic chunk: {chunk}. Error: {e}")
return cleaned_chunk.strip()
Expand Down