yym68686 commited on
Commit
5200484
·
1 Parent(s): 47f4668

Fix the bug of non-standard SSE format in Claude API response data parsing and improve robustness.

Browse files
Files changed (1) hide show
  1. response.py +3 -1
response.py CHANGED
@@ -104,7 +104,9 @@ async def fetch_claude_response_stream(client, url, headers, payload, model):
104
  # print(line)
105
 
106
  if line.startswith("data:"):
107
- line = line[6:]
 
 
108
  resp: dict = json.loads(line)
109
  message = resp.get("message")
110
  if message:
 
104
  # print(line)
105
 
106
  if line.startswith("data:"):
107
+ line = line[5:]
108
+ if line.startswith(" "):
109
+ line = line[1:]
110
  resp: dict = json.loads(line)
111
  message = resp.get("message")
112
  if message: