From 8804c88450e4a1b6c8ab2ce1b433d073c4a9624d Mon Sep 17 00:00:00 2001
From: zhaoqingang <zhaoqg0118@163.com>
Date: 星期一, 25 十一月 2024 14:58:36 +0800
Subject: [PATCH] dify test

---
 app/service/difyService.py |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/app/service/difyService.py b/app/service/difyService.py
index 3e588cf..d3b4b20 100644
--- a/app/service/difyService.py
+++ b/app/service/difyService.py
@@ -5,6 +5,8 @@
 from typing import Union, Dict, List
 from fastapi import HTTPException
 from starlette import status
+
+from Log import logger
 from app.config.config import settings
 from app.utils.rsa_crypto import RagflowCrypto
 
@@ -62,7 +64,7 @@
                 raise Exception("Authorization header not found in response")
             return authorization
 
-    async def chat(self, token: str, chat_id: str,  message: str, upload_file_id: str, conversation_id: str):
+    async def chat(self, token: str, user_id: int,  message: str, upload_file_id: str, conversation_id: str):
 
         target_url = f"{self.base_url}/v1/chat-messages"
         files = []
@@ -79,8 +81,8 @@
             "inputs": {},
             "query": message,
             "response_mode": "streaming",
-            "conversation_id": conversation_id,
-            "user": chat_id,
+            "conversation_id": "",
+            "user": str(user_id),
             "files": files
         }
 
@@ -93,7 +95,7 @@
                 if response.status_code == 200:
                     try:
                         async for answer in response.aiter_text():
-                            print(f"response of ragflow chat: {answer}")
+                            # print(f"response of ragflow chat: {answer}")
                             yield answer
                     except GeneratorExit as e:
                         print(e)
@@ -114,18 +116,23 @@
                 return data
             return data.get("message", [])
 
-    async def upload(self, token: str, filename: str, file: bytes) -> dict:
-        url = f"{self.base_url}/console/api/files/upload"
+    async def upload(self, token: str, filename: str, file: bytes, user_id) -> dict:
+        url = f"{self.base_url}/v1/files/upload"
         headers = {
-            'Content-Type': 'application/json',
+            # 'Content-Type': 'application/json',
             'Authorization': f'Bearer {token}'
         }
-
+        data = {
+            'user': str(user_id)
+        }
         # 鍒涘缓琛ㄥ崟鏁版嵁锛屽寘鍚枃浠�
         files = {"file": (filename, file)}
         async with httpx.AsyncClient() as client:
-            response = await client.post(url, headers=headers, files=files)
+            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

--
Gitblit v1.8.0