x
This commit is contained in:
@@ -79,6 +79,7 @@ class LLMClient:
|
||||
response.raise_for_status()
|
||||
# 实时迭代流式响应
|
||||
async for line in response.content.iter_chunked(LLM_CONFIG["stream_chunk_size"]):
|
||||
|
||||
if not line:
|
||||
continue
|
||||
line_data = line.decode("utf-8")
|
||||
@@ -95,13 +96,14 @@ class LLMClient:
|
||||
res_conversation_id = data["conversation_id"]
|
||||
# 提取内容
|
||||
chunk = data.get("content", data.get("answer", data.get("message", "")))
|
||||
# print('大模型返回的', chunk)
|
||||
if chunk:
|
||||
full_response += chunk
|
||||
if stream_callback:
|
||||
await stream_callback(chunk, res_conversation_id, False)
|
||||
await asyncio.sleep(0) # 让出调度权
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"解析流式数据失败: {e}")
|
||||
# print(f"大模型解析流式数据失败: {e}")
|
||||
continue
|
||||
else:
|
||||
# 异步非流式请求
|
||||
|
||||
Reference in New Issue
Block a user