fix:coze-studio api done return data is none and event done char not … (#1758)

* fix:coze-studio api done return data is none and event done char not is "done"

* Update pkg/provider/runners/cozeapi.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Junyan Qin (Chin) <rockchinq@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
fdc310
2025-11-07 15:17:00 +08:00
committed by GitHub
parent a076ce5756
commit c893ffc177
2 changed files with 4 additions and 3 deletions

View File

@@ -178,7 +178,7 @@ class AsyncCozeAPIClient:
elif chunk.startswith("data:"):
chunk_data = chunk.replace("data:", "", 1).strip()
else:
yield {"event": chunk_type, "data": json.loads(chunk_data)}
yield {"event": chunk_type, "data": json.loads(chunk_data) if chunk_data else {}} # 处理本地部署时接口返回的data为空值
except asyncio.TimeoutError:
raise Exception(f"Coze API 流式请求超时 ({timeout}秒)")

View File

@@ -152,6 +152,7 @@ class CozeAPIRunner(runner.RequestRunner):
event_type = chunk.get('event')
data = chunk.get('data', {})
# Removed debug print statement to avoid cluttering logs in production
if event_type == 'conversation.message.delta':
# 收集内容
@@ -162,7 +163,7 @@ class CozeAPIRunner(runner.RequestRunner):
if 'reasoning_content' in data:
full_reasoning += data.get('reasoning_content', '')
elif event_type == 'done':
elif event_type.split(".")[-1] == 'done' : # 本地部署coze时结束event不为done
# 保存会话ID
if 'conversation_id' in data:
conversation_id = data.get('conversation_id')
@@ -258,7 +259,7 @@ class CozeAPIRunner(runner.RequestRunner):
stop_reasoning = True
elif event_type == 'done':
elif event_type.split(".")[-1] == 'done' : # 本地部署coze时结束event不为done
# 保存会话ID
if 'conversation_id' in data:
conversation_id = data.get('conversation_id')