From 1ab90de913405b45050e0f732a03004087134fda Mon Sep 17 00:00:00 2001
From: zhaoqingang <zhaoqg0118@163.com>
Date: 星期一, 25 十一月 2024 11:11:04 +0800
Subject: [PATCH] 上传dify文件
---
app/service/difyService.py | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/app/service/difyService.py b/app/service/difyService.py
index 3e588cf..0444387 100644
--- a/app/service/difyService.py
+++ b/app/service/difyService.py
@@ -62,7 +62,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 = []
@@ -80,7 +80,7 @@
"query": message,
"response_mode": "streaming",
"conversation_id": conversation_id,
- "user": chat_id,
+ "user": str(user_id),
"files": files
}
@@ -114,17 +114,19 @@
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)
# file_path = data.get("file_path", "")
result = {
--
Gitblit v1.8.0