add
This commit is contained in:
@@ -184,15 +184,15 @@ class Anthropic(Platform):
|
|||||||
async with self.http.post(endpoint, headers=headers, data=json.dumps(req_body)) as response:
|
async with self.http.post(endpoint, headers=headers, data=json.dumps(req_body)) as response:
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
raise ValueError(f"Error: {await response.text()}")
|
raise ValueError(f"Error: {await response.text()}")
|
||||||
async for line_bytes in response.content:
|
async for line_bytes in response.content.iter_lines():
|
||||||
line = line_bytes.decode("utf-8").strip()
|
line = line_bytes.decode("utf-8").strip()
|
||||||
if not line.startswith("data: "):
|
if not line.startswith("data: "):
|
||||||
continue
|
continue
|
||||||
data_str = line[6:]
|
data_str = line[6:]
|
||||||
if data_str == "[DONE]":
|
|
||||||
break
|
|
||||||
try:
|
try:
|
||||||
data = json.loads(data_str)
|
data = json.loads(data_str)
|
||||||
|
if data.get("type") == "message_stop":
|
||||||
|
break
|
||||||
if data.get("type") == "content_block_delta":
|
if data.get("type") == "content_block_delta":
|
||||||
delta = data.get("delta", {})
|
delta = data.get("delta", {})
|
||||||
if delta.get("type") == "text_delta":
|
if delta.get("type") == "text_delta":
|
||||||
|
|||||||
Reference in New Issue
Block a user