zhangqian
2024-10-12 612d51a591abf0745d8186516f322a8944449ba7
app/api/chat.py
@@ -47,6 +47,7 @@
                    message = await websocket.receive_json()
                    print(f"Received from client {chat_id}: {message}")
                    async for rag_response in ragflow_service.chat(token, chat_id, message["chatHistory"]):
                        try:
                        print(f"Received from ragflow: {rag_response}")
                        json_str = rag_response[5:].strip()
                        json_data = json.loads(json_str)
@@ -57,7 +58,8 @@
                            result = {"message": "", "type": "close"}
                        await websocket.send_json(result)
                        print(f"Forwarded to client {chat_id}: {result}")
                        except Exception as e:
                            print(f"Error forwarding message to ragflow: {e}")
            # 启动任务处理客户端消息
            tasks = [
                asyncio.create_task(forward_to_ragflow())