From 56d8dce48022692c5a7541114ef84f4fa395ff9d Mon Sep 17 00:00:00 2001
From: zhaoqingang <zhaoqg0118@163.com>
Date: 星期二, 26 十一月 2024 11:22:49 +0800
Subject: [PATCH] dify images 问题

---
 app/service/difyService.py |   37 +++++++++++++++++++------------------
 1 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/app/service/difyService.py b/app/service/difyService.py
index d3b4b20..9aee918 100644
--- a/app/service/difyService.py
+++ b/app/service/difyService.py
@@ -17,6 +17,8 @@
 
     def _handle_response(self, response: httpx.Response) -> Union[Dict, List]:
         if response.status_code != 200:
+            if response.status_code == 201:
+                return response.json()
             return {}
 
         data = response.json()
@@ -26,8 +28,8 @@
                 status_code=status.HTTP_401_UNAUTHORIZED,
                 detail="鐧诲綍杩囨湡",
             )
-        if ret_code != 0:
-            return {}
+        # if ret_code != 0:
+        #     return {}
 
         # 妫�鏌ヨ繑鍥炵殑鏁版嵁绫诲瀷
         if isinstance(data.get("data"), dict):
@@ -35,7 +37,7 @@
         elif isinstance(data.get("data"), list):
             return data.get("data", [])
         else:
-            return {}
+            return data
 
     async def register(self, username: str, password: str):
         password = RagflowCrypto(settings.PUBLIC_KEY, settings.PRIVATE_KEY).encrypt(password)
@@ -105,16 +107,22 @@
 
 
 
-    async def get_session_history(self, token: str, chat_id: str, is_all: int=0):
-        url = f"{self.base_url}/v1/conversation/get?conversation_id={chat_id}"
-        headers = {"Authorization": token}
+    async def get_session_history(self, token: str, conversation_id: str, user: str):
+        url = f"{self.base_url}/v1/messages"
+        params = {
+            'user': user,
+            'conversation_id': conversation_id
+        }
+        headers = {"Authorization": f'Bearer {token}'}
         async with httpx.AsyncClient() as client:
-            response = await client.get(url, headers=headers)
+            response = await client.get(url, params=params, headers=headers)
+            # print(response.text)
+            # print(response.status_code)
+            # print(response.res)
             data = self._handle_response(response)
             # print("----------------data----------------------:", data)
-            if is_all:
-                return data
-            return data.get("message", [])
+
+            return data
 
     async def upload(self, token: str, filename: str, file: bytes, user_id) -> dict:
         url = f"{self.base_url}/v1/files/upload"
@@ -130,15 +138,8 @@
         async with httpx.AsyncClient() as client:
             response = await client.post(url, headers=headers, files=files, data=data)
             data = self._handle_response(response)
-            logger.error("----------------------------ffff-------------------------------")
-            logger.error(response.status_code)
-            logger.error(response.text)
-            # file_path = data.get("file_path", "")
-            result = {
-                "file_path": data
-            }
 
-            return result
+            return data
 
 
 

--
Gitblit v1.8.0