| | |
| | | print(f"Error process message of ragflow: {e2}") |
| | | elif agent.type == "reportWorkflow": |
| | | |
| | | token = DfTokenDao(db).get_token_by_id(DOCUMENT_TO_CLEANING) |
| | | if not token: |
| | | await websocket.send_json({"message": "Invalid token document_to_cleaning", "type": "error"}) |
| | | |
| | | while True: |
| | | receive_message = await websocket.receive_json() |
| | | print(f"Received from client {chat_id}: {receive_message}") |
| | |
| | | inputs_list = [] |
| | | is_next = 0 |
| | | if workflow_type == 1: |
| | | token = DfTokenDao(db).get_token_by_id(DOCUMENT_TO_CLEANING) |
| | | if not token: |
| | | await websocket.send_json( |
| | | {"message": "Invalid token document_to_cleaning", "type": "error"}) |
| | | inputs["input_files"] = files |
| | | inputs["Completion_of_main_indicators"] = title |
| | | inputs_list.append({"inputs": inputs, "token": token, "workflow_type": workflow_type}) |
| | |
| | | {"message": "Invalid token document_to_title", "type": "error"}) |
| | | inputs_list.append({"inputs": inputs, "token": token, "workflow_type": workflow_type}) |
| | | elif workflow_type == 3 and is_clean == 1 or tokens >= max_token: |
| | | token = DfTokenDao(db).get_token_by_id(DOCUMENT_TO_CLEANING) |
| | | if not token: |
| | | await websocket.send_json( |
| | | {"message": "Invalid token document_to_cleaning", "type": "error"}) |
| | | inputs["input_files"] = files |
| | | inputs["Completion_of_main_indicators"] = title |
| | | inputs_list.append({"inputs": inputs, "token": token, "workflow_type": 1}) |
| | |
| | | workflow_dict = {} |
| | | if input["workflow_type"] == 1 or input["workflow_type"] == 2: |
| | | async for rag_response in dify_service.workflow(input["token"], current_user.id, i): |
| | | print(rag_response) |
| | | # print(rag_response) |
| | | try: |
| | | if rag_response[:5] == "data:": |
| | | # 如果是,则截取掉前5个字符,并去除首尾空白符 |
| | |
| | | node_data["data"]["outputs"] = {} |
| | | if "inputs" in node_data["data"]: |
| | | node_data["data"]["inputs"] = {} |
| | | print(node_data) |
| | | # print(node_data) |
| | | node_list.append(node_data) |
| | | |
| | | complete_response = "" |
| | |
| | | |
| | | message = answer.get("title", "") |
| | | |
| | | result = {"message": message, "type": "system"} |
| | | |
| | | result = {"message": message, "type": "system", "workflow":{"node_data": workflow_list}} |
| | | elif data.get("event") == "node_finished": |
| | | workflow_list.append({ |
| | | "title": data.get("data", {}).get("title", ""), |
| | |
| | | "elapsed_time":data.get("data", {}).get("elapsed_time", 0), |
| | | "error":data.get("data", {}).get("error", ""), |
| | | }) |
| | | answer = data.get("data", "") |
| | | if isinstance(answer, str): |
| | | logger.error("----------------未知数据--------------------") |
| | | logger.error(data) |
| | | continue |
| | | elif isinstance(answer, dict): |
| | | |
| | | message = answer.get("title", "") |
| | | if answer.get("status") == "failed": |
| | | message = answer.get("error", "") |
| | | result = {"message": message, "type": "system", "workflow":{"node_data": workflow_list}} |
| | | |
| | | elif data.get("event") == "workflow_finished": |
| | | answer = data.get("data", "") |
| | | if isinstance(answer, str): |
| | |
| | | "error": answer.get("error", ""), |
| | | "elapsed_time": answer.get("elapsed_time", 0) |
| | | } |
| | | result = {"message": message, "type": "message", "download_url": download_url} |
| | | result = {"message": message, "type": "message", "download_url": download_url, "workflow":workflow_dict} |
| | | try: |
| | | SessionService(db).update_session(chat_id, |
| | | message={"role": "assistant", |
| | |
| | | "conversation_id")) |
| | | node_list = [] |
| | | except Exception as e: |
| | | logger.error("保存dcd ify的会话异常!") |
| | | logger.error("保存dify的会话异常!") |
| | | logger.error(e) |
| | | try: |
| | | await websocket.send_json(result) |
| | |
| | | node_data["data"]["outputs"] = {} |
| | | if "inputs" in node_data["data"]: |
| | | node_data["data"]["inputs"] = {} |
| | | print(node_data) |
| | | # print(node_data) |
| | | node_list.append(node_data) |
| | | complete_response = "" |
| | | if data.get("event") == "node_started": # "event": "message_end" |
| | |
| | | |
| | | message = answer.get("title", "") |
| | | |
| | | result = {"message": message, "type": "system"} |
| | | result = {"message": message, "type": "system", "workflow":{"node_data": workflow_list}} |
| | | elif data.get("event") == "node_finished": |
| | | workflow_list.append({ |
| | | "title": data.get("data", {}).get("title", ""), |
| | |
| | | "elapsed_time":data.get("data", {}).get("elapsed_time", 0), |
| | | "error":data.get("data", {}).get("error", ""), |
| | | }) |
| | | |
| | | answer = data.get("data", "") |
| | | if isinstance(answer, str): |
| | | logger.error("----------------未知数据--------------------") |
| | | logger.error(data) |
| | | continue |
| | | elif isinstance(answer, dict): |
| | | |
| | | message = answer.get("title", "") |
| | | if answer.get("status") == "failed": |
| | | message = answer.get("error", "") |
| | | result = {"message": message, "type": "system", "workflow":{"node_data": workflow_list}} |
| | | elif data.get("event") == "message": |
| | | answer_str = data.get("answer", "") |
| | | # try: |
| | |
| | | # print(e) |
| | | # continue |
| | | result = {"message": answer_str, "type": "message", |
| | | "download_url": ""} |
| | | "download_url": "", "workflow": {"node_data": workflow_list}} |
| | | |
| | | # try: |
| | | # await websocket.send_json(result) |