Skip to content

Commit

Permalink
Fix the bug of non-standard SSE format in Claude API response data pa…
Browse files Browse the repository at this point in the history
…rsing and improve robustness.
  • Loading branch information
yym68686 committed Jul 23, 2024
1 parent 47f4668 commit 5200484
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion response.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ async def fetch_claude_response_stream(client, url, headers, payload, model):
# print(line)

if line.startswith("data:"):
line = line[6:]
line = line[5:]
if line.startswith(" "):
line = line[1:]
resp: dict = json.loads(line)
message = resp.get("message")
if message:
Expand Down

0 comments on commit 5200484

Please sign in to comment.