| | |
| | | } |
| | | token = DfTokenDao(db).get_token_by_id(token_dict[chat_type]) |
| | | # print(token) |
| | | node_list = [] |
| | | if not token: |
| | | await websocket.send_json({"message": "Invalid token", "type": "error"}) |
| | | |
| | |
| | | complete_response += rag_response |
| | | try: |
| | | data = json.loads(complete_response) |
| | | node_data = deepcopy(data) |
| | | if "data" in node_data: |
| | | if "outputs" in node_data["data"]: |
| | | node_data["data"]["outputs"] = {} |
| | | if "inputs" in node_data["data"]: |
| | | node_data["data"]["inputs"] = {} |
| | | # print(node_data) |
| | | node_list.append(node_data) |
| | | if data.get("event") == "node_started" or data.get( |
| | | "event") == "node_finished": # "event": "message_end" |
| | | if "data" not in data or not data["data"]: # 信息过滤 |
| | |
| | | # 正常输出 |
| | | answer = data.get("answer", "") |
| | | result = {"message": answer, "type": "stream"} |
| | | elif data.get("event") == "error": # "event": "message_end" |
| | | # 正常输出 |
| | | answer = data.get("message", "") |
| | | result = {"message": answer, "type": "system"} |
| | | elif data.get("event") == "workflow_finished": |
| | | answer = data.get("data", "") |
| | | if isinstance(answer, str): |
| | |
| | | message={"role": "assistant", |
| | | "content": { |
| | | "answer": message, |
| | | "node_list": node_list, |
| | | "download_url": download_url}}, |
| | | conversation_id=data.get( |
| | | "conversation_id")) |
| | | node_list = [] |
| | | except Exception as e: |
| | | logger.error("保存dify的会话异常!") |
| | | logger.error(e) |
| | |
| | | return Response(code=400, msg="The password must be at least 8 and contain both numbers and letters") |
| | | db_user = db.query(UserModel).filter(UserModel.username == user.userName, UserModel.status != USER_STATSU_DELETE).first() |
| | | if db_user: |
| | | return Response(code=200, msg="user already created") |
| | | return Response(code=400, msg="user already created") |
| | | pwd = user.pwd |
| | | if not pwd: |
| | | pwd = "basic123456" |
| | |
| | | "rank": 97, |
| | | "dialog": [ |
| | | { |
| | | "id": "7638f006-38a2-4c21-a68e-c6c49b304a35", |
| | | "chat_id": "7638f006-38a2-4c21-a68e-c6c49b304a35", |
| | | "id": "e138dd77-34d9-40f8-88f8-4d0ba7842b0b", |
| | | "chat_id": "e138dd77-34d9-40f8-88f8-4d0ba7842b0b", |
| | | "chat_type": "documentIa", |
| | | "agentType": 4 |
| | | } |
| | |
| | | "rank": 90, |
| | | "dialog": [ |
| | | { |
| | | "id": "e138dd77-34d9-40f8-88f8-4d0ba7842b0b", |
| | | "chat_id": "e138dd77-34d9-40f8-88f8-4d0ba7842b0b", |
| | | "id": "7638f006-38a2-4c21-a68e-c6c49b304a35", |
| | | "chat_id": "7638f006-38a2-4c21-a68e-c6c49b304a35", |
| | | "chat_type": "documentIaDs", |
| | | "agentType": 4 |
| | | } |