Browse Source

commit

tmp
zhaoqingang 1 year ago
parent
commit
247038b7ee
3 changed files with 20 additions and 5 deletions
  1. 15 0
      app/api/chat.py
  2. 1 1
      app/api/user.py
  3. 4 4
      app/config/env_conf/menu_conf.json

+ 15 - 0
app/api/chat.py

@@ -815,6 +815,7 @@ async def handle_client(websocket: WebSocket,
                     }
                     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"})
 
@@ -867,6 +868,14 @@ async def handle_client(websocket: WebSocket,
                                     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"]:  # 信息过滤
@@ -891,6 +900,10 @@ async def handle_client(websocket: WebSocket,
                                         # 正常输出
                                         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):
@@ -913,9 +926,11 @@ async def handle_client(websocket: WebSocket,
                                                                                   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)

+ 1 - 1
app/api/user.py

@@ -30,7 +30,7 @@ async def add_user(user: UserInfo, current_user: UserModel = Depends(get_current
             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"

+ 4 - 4
app/config/env_conf/menu_conf.json

@@ -44,8 +44,8 @@
       "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
         }
@@ -175,8 +175,8 @@
       "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
         }