Fix the bug of non-standard SSE format in Claude API response data parsing and improve robustness.
Browse files- 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[
|
|
|
|
|
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:
|