|
@@ -62,7 +62,7 @@ class DifyService:
|
|
|
raise Exception("Authorization header not found in response")
|
|
raise Exception("Authorization header not found in response")
|
|
|
return authorization
|
|
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"
|
|
target_url = f"{self.base_url}/v1/chat-messages"
|
|
|
files = []
|
|
files = []
|
|
@@ -80,7 +80,7 @@ class DifyService:
|
|
|
"query": message,
|
|
"query": message,
|
|
|
"response_mode": "streaming",
|
|
"response_mode": "streaming",
|
|
|
"conversation_id": conversation_id,
|
|
"conversation_id": conversation_id,
|
|
|
- "user": chat_id,
|
|
|
|
|
|
|
+ "user": str(user_id),
|
|
|
"files": files
|
|
"files": files
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -114,17 +114,19 @@ class DifyService:
|
|
|
return data
|
|
return data
|
|
|
return data.get("message", [])
|
|
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 = {
|
|
headers = {
|
|
|
- 'Content-Type': 'application/json',
|
|
|
|
|
|
|
+ # 'Content-Type': 'application/json',
|
|
|
'Authorization': f'Bearer {token}'
|
|
'Authorization': f'Bearer {token}'
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ data = {
|
|
|
|
|
+ 'user': str(user_id)
|
|
|
|
|
+ }
|
|
|
# 创建表单数据,包含文件
|
|
# 创建表单数据,包含文件
|
|
|
files = {"file": (filename, file)}
|
|
files = {"file": (filename, file)}
|
|
|
async with httpx.AsyncClient() as client:
|
|
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)
|
|
data = self._handle_response(response)
|
|
|
# file_path = data.get("file_path", "")
|
|
# file_path = data.get("file_path", "")
|
|
|
result = {
|
|
result = {
|