| | |
| | | agent = db.query(AgentModel).filter(AgentModel.id == agent_id).first() |
| | | if not agent: |
| | | ret = {"message": "Agent not found", "type": "close"} |
| | | return websocket.send_json(ret) |
| | | await websocket.send_json(ret) |
| | | return |
| | | agent_type = agent.agent_type |
| | | if chat_id == "" or chat_id == "0": |
| | | ret = {"message": "Chat ID not found", "type": "close"} |
| | | return websocket.send_json(ret) |
| | | await websocket.send_json(ret) |
| | | return |
| | | |
| | | if agent_type == AgentType.RAGFLOW: |
| | | ragflow_service = RagflowService(settings.ragflow_base_url) |
| | |
| | | if len(chat_history) == 0: |
| | | result = {"message": "内部错误:创建会话失败", "type": "close"} |
| | | await websocket.send_json(result) |
| | | continue |
| | | async for rag_response in ragflow_service.chat(token, chat_id, chat_history): |
| | | try: |
| | | print(f"Received from ragflow: {rag_response}") |
| | |
| | | print(f"Client {chat_id} disconnected") |
| | | else: |
| | | ret = {"message": "Agent not found", "type": "close"} |
| | | return websocket.send_json(ret) |
| | | await websocket.send_json(ret) |
| | | |