Skip to content

Commit 9ae1c31

Browse files
authored
Use non-strict JSON loading in Anthropic chunk responses (#1130)
This allows us to be able to parse multi-line code chunks that Anthropic outputs. Signed-off-by: Juan Antonio Osorio <[email protected]>
1 parent b00ca97 commit 9ae1c31

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/codegate/muxing/adapter.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ def _format_antropic(self, chunk: str) -> str:
101101
"""
102102
cleaned_chunk = chunk.split("data:")[1].strip()
103103
try:
104-
chunk_dict = json.loads(cleaned_chunk)
104+
# Use `strict=False` to allow the JSON payload to contain
105+
# newlines, tabs and other valid characters that might
106+
# come from Anthropic returning code.
107+
chunk_dict = json.loads(cleaned_chunk, strict=False)
105108
except Exception as e:
106109
logger.warning(f"Error parsing Anthropic chunk: {chunk}. Error: {e}")
107110
return cleaned_chunk.strip()

0 commit comments

Comments
 (0)