|
|
@@ -51,14 +51,20 @@ async def handle_client(websocket: WebSocket,
|
|
|
print(f"Received from ragflow: {rag_response}")
|
|
|
json_str = rag_response[5:].strip()
|
|
|
json_data = json.loads(json_str)
|
|
|
- if json_data.get("data") is not True:
|
|
|
+ data = json_data.get("data")
|
|
|
+ if data is True: # 完成输出
|
|
|
+ result = {"message": "", "type": "close"}
|
|
|
+ elif data is None: # 发生错误
|
|
|
+ answer = json_data.get("retmsg", json_data.get("retcode"))
|
|
|
+ result = {"message": "内部错误:" + answer, "type": "stream"}
|
|
|
+ else: # 正常输出
|
|
|
answer = json_data.get("data", {}).get("answer", "")
|
|
|
result = {"message": answer, "type": "stream"}
|
|
|
- else:
|
|
|
- result = {"message": "", "type": "close"}
|
|
|
await websocket.send_json(result)
|
|
|
print(f"Forwarded to client {chat_id}: {result}")
|
|
|
except Exception as e:
|
|
|
+ result = {"message": f"内部错误: {e}", "type": "close"}
|
|
|
+ await websocket.send_json(result)
|
|
|
print(f"Error forwarding message to ragflow: {e}")
|
|
|
# 启动任务处理客户端消息
|
|
|
tasks = [
|