| | |
| | | from app.api import get_current_user_websocket |
| | | from app.config.config import settings |
| | | from app.config.const import IMAGE_TO_TEXT, DOCUMENT_TO_REPORT, DOCUMENT_TO_CLEANING |
| | | from app.models import MenuCapacityModel |
| | | from app.models.agent_model import AgentModel, AgentType |
| | | from app.models.base_model import get_db |
| | | from app.models.user_model import UserModel |
| | |
| | | tasks = [] |
| | | await websocket.accept() |
| | | print(f"Client {agent_id} connected") |
| | | |
| | | agent = db.query(AgentModel).filter(AgentModel.id == agent_id).first() |
| | | agent = db.query(MenuCapacityModel).filter(MenuCapacityModel.chat_id == agent_id).first() |
| | | if not agent: |
| | | agent = db.query(AgentModel).filter(AgentModel.id == agent_id).first() |
| | | agent_type = agent.agent_type |
| | | chat_type = agent.type |
| | | else: |
| | | agent_type = agent.capacity_type |
| | | chat_type = agent.chat_type |
| | | if not agent: |
| | | ret = {"message": "Agent not found", "type": "close"} |
| | | await websocket.send_json(ret) |
| | | return |
| | | print(1111) |
| | | agent_type = agent.agent_type |
| | | print(agent_type) |
| | | |
| | | if chat_id == "" or chat_id == "0": |
| | | ret = {"message": "Chat ID not found", "type": "close"} |
| | | await websocket.send_json(ret) |
| | | return |
| | | |
| | | if agent_type == AgentType.RAGFLOW: |
| | | print(222) |
| | | ragflow_service = RagflowService(settings.fwr_base_url) |
| | | token = await get_ragflow_token(db, current_user.id) |
| | | try: |
| | |
| | | await websocket.send_json({"message": "Invalid request", "type": "error"}) |
| | | continue |
| | | logger.error(agent.type) |
| | | if agent.type == "questionTalk": |
| | | if chat_type == "questionTalk": |
| | | |
| | | try: |
| | | data = await service.questions_talk(question, chat_id) |
| | |
| | | # token = get_dify_token(db, current_user.id) |
| | | try: |
| | | async def forward_to_dify(): |
| | | if agent.type == "imageTalk": |
| | | if chat_type == "imageTalk": |
| | | token = DfTokenDao(db).get_token_by_id(IMAGE_TO_TEXT) |
| | | if not token: |
| | | await websocket.send_json({"message": "Invalid token", "type": "error"}) |
| | |
| | | result = {"message": f"内部错误: {e2}", "type": "close"} |
| | | await websocket.send_json(result) |
| | | print(f"Error process message of ragflow: {e2}") |
| | | elif agent.type == "reportWorkflow": |
| | | elif chat_type == "reportWorkflow": |
| | | |
| | | token = DfTokenDao(db).get_token_by_id(DOCUMENT_TO_CLEANING) |
| | | if not token: |