fix: 添加缺失的 parse_sse_events 函数到 core.py
This commit is contained in:
@@ -205,6 +205,25 @@ def http_stream_request(
|
||||
)
|
||||
|
||||
|
||||
def parse_sse_events(response_text: str) -> List[str]:
|
||||
"""从 SSE 响应文本中解析出所有 data 事件的数据。
|
||||
|
||||
Args:
|
||||
response_text: SSE 响应的原始文本
|
||||
|
||||
Returns:
|
||||
data 字段内容的列表(已跳过 [DONE])
|
||||
"""
|
||||
events = []
|
||||
for line in response_text.split("\n"):
|
||||
line = line.strip()
|
||||
if line.startswith("data:"):
|
||||
data = line[len("data:"):].strip()
|
||||
if data and data != "[DONE]":
|
||||
events.append(data)
|
||||
return events
|
||||
|
||||
|
||||
def format_json(text: str) -> str:
|
||||
"""格式化 JSON 文本(用于美化输出)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user