From 6be3990bfe27b798b19cc257af468f2a3c41e8e5 Mon Sep 17 00:00:00 2001
From: zhaoqingang <zhaoqg0118@163.com>
Date: 星期一, 25 十一月 2024 12:02:50 +0800
Subject: [PATCH] dify 对话测试

---
 app/api/chat.py |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/app/api/chat.py b/app/api/chat.py
index 2932d45..2a511e1 100644
--- a/app/api/chat.py
+++ b/app/api/chat.py
@@ -314,7 +314,9 @@
                     except Exception as e:
                         logger.error(e)
                     complete_response = ""
-                    async for rag_response in dify_service.chat(token, chat_id, question, upload_file_id, conversation_id):
+                    async for rag_response in dify_service.chat(token, current_user.id, question, upload_file_id, conversation_id):
+                        logger.error("=============================================")
+                        logger.error(rag_response)
                         try:
                             if rag_response[:5] == "data:":
                                 # 濡傛灉鏄紝鍒欐埅鍙栨帀鍓�5涓瓧绗︼紝骞跺幓闄ら灏剧┖鐧界
@@ -326,7 +328,9 @@
                             try:
                                 data = json.loads(complete_response)
                                 # data = json_data.get("data")
-                                if "answer" not in  data or isinstance(data["answer"], dict):  # 淇℃伅杩囨护
+                                if "answer" not in  data or not isinstance(data["answer"], dict):  # 淇℃伅杩囨护
+                                    logger.error("闈炴硶鏁版嵁--------------------")
+                                    logger.error(data)
                                     continue
                                 else:  # 姝e父杈撳嚭
                                     answer = data.get("answer", "")
@@ -336,6 +340,7 @@
                                         SessionService(db).update_session(chat_id,
                                                                           message={"role": "assistant", "content": data, "conversation_id": data.get("conversation_id")})
                                     except Exception as e:
+                                        logger.error("淇濆瓨dify鐨勪細璇濆紓甯革紒")
                                         logger.error(e)
                                 await websocket.send_json(result)
                                 complete_response = ""
@@ -346,12 +351,7 @@
                             result = {"message": f"鍐呴儴閿欒锛� {e2}", "type": "close"}
                             await websocket.send_json(result)
                             print(f"Error process message of ragflow: {e2}")
-                    try:
-                        dialog_chat_history = await ragflow_service.get_session_history(token, chat_id, 1)
-                        await update_session_history(db, dialog_chat_history, current_user.id)
-                    except Exception as e:
-                        logger.error(e)
-                        logger.error("-----------------淇濆瓨ragflow鐨勫巻鍙蹭細璇濆紓甯�-----------------")
+
 
             # 鍚姩浠诲姟澶勭悊瀹㈡埛绔秷鎭�
             tasks = [

--
Gitblit v1.8.0