From 519930bc1112cdf7881fecce907381ce6374e74c Mon Sep 17 00:00:00 2001
From: zhaoqingang <zhaoqg0118@163.com>
Date: 星期二, 14 一月 2025 13:37:56 +0800
Subject: [PATCH] 文档出卷-未上传文件提示
---
app/service/difyService.py | 54 ++++++++++++++++++++++--------------------------------
1 files changed, 22 insertions(+), 32 deletions(-)
diff --git a/app/service/difyService.py b/app/service/difyService.py
index 7329640..3c67d09 100644
--- a/app/service/difyService.py
+++ b/app/service/difyService.py
@@ -9,6 +9,7 @@
# from Log import logger
from app.config.config import settings
+# from app.service.service_token import get_admin_token
from app.utils.rsa_crypto import RagflowCrypto
@@ -41,9 +42,9 @@
return data
async def register(self, username: str, password: str, token=None):
- if not token:
- token = await get_df_token()
- email = f"{username}@df.com"
+ # if not token:
+ # token = await get_admin_token()
+ email = f"{username}@basic.com"
invite_res = await self.invite_workspaces_member(token, [email], "admin")
# print(invite_res)
if invite_res.get("result") != "success" or not invite_res.get("invitation_results"):
@@ -54,7 +55,7 @@
# print(invite_token)
if not invite_token:
return {}
- await self.login(email, password, True, invite_token)
+ await self.login(username, password, True, invite_token)
activate_res = await self.activate(email, username, invite_token, "", "")
activate_res["email"] = email
activate_res["id"] = invite_token
@@ -68,12 +69,12 @@
headers={'Content-Type': 'application/json',"Authorization": f'Bearer {token}'},
json={"emails": emails, "language": "zh-Hans", "role": role}
)
- print(response.text)
+ # print(response.text)
return self._handle_response(response)
- async def login(self, email: str, password: str, remember_me,invite_token:str="") -> str:
+ async def login(self, username: str, password: str, remember_me=True, invite_token:str="") -> str:
# password = RagflowCrypto(settings.PUBLIC_KEY, settings.PRIVATE_KEY).encrypt(password)
- data = {"email": email, "password": password, "remember_me": remember_me, "invite_token": invite_token,
+ data = {"email": f"{username}@basic.com", "password": password, "remember_me": remember_me, "invite_token": invite_token,
"language": "zh-Hans"}
async with httpx.AsyncClient() as client:
@@ -84,7 +85,8 @@
)
if response.status_code != 200:
raise Exception(f"df login failed: {response.text}")
- return self._handle_response(response)
+ data = self._handle_response(response)
+ return data.get('access_token')
async def email_check(self, token, email: str):
async with httpx.AsyncClient() as client:
@@ -98,7 +100,7 @@
# password = RagflowCrypto(settings.PUBLIC_KEY, settings.PRIVATE_KEY).encrypt(password)
data = {"email": email, "name": name, "token": token, # "workspace_id": workspace_id,
"interface_language": "en-US", "timezone": "Asia/Shanghai"}
- print(data)
+ # print(data)
async with httpx.AsyncClient() as client:
response = await client.post(
f"{self.base_url}/console/api/activate",
@@ -111,7 +113,7 @@
async def invite_member_activate(self, token:str, email: str, name: str, password:str) -> str:
invite_res = await self.invite_workspaces_member(token, [email], "admin")
- print(invite_res)
+ # print(invite_res)
if invite_res.get("result") != "success" or not invite_res.get("invitation_results"):
# logger.error(invite_res)
return {}
@@ -125,21 +127,10 @@
- async def chat(self, token: str, user_id: int, message: str, upload_file_id: str, conversation_id: str):
-
+ async def chat(self, token: str, user_id: int, message: str, files: [], conversation_id: str, inputs: dict):
target_url = f"{self.base_url}/v1/chat-messages"
- files = []
- if upload_file_id:
- files = [
- {
- "type": "image",
- "transfer_method": "local_file",
- "url": "",
- "upload_file_id": upload_file_id
- }
- ]
data = {
- "inputs": {},
+ "inputs": inputs,
"query": message,
"response_mode": "streaming",
"conversation_id": conversation_id,
@@ -252,10 +243,9 @@
# b = await a.email_check(
# "ebd36739-0272-4b3f-95ab-0c6ac1639831",
# "test05@163.com")
- # b = await a.login(
- # "test05@163.com",
- # "zhaoqg123456",
- # True, "ebd36739-0272-4b3f-95ab-0c6ac1639831")
+ b = await a.login(
+ "zhao1234567",
+ "zhaoqg123456")
@@ -263,11 +253,11 @@
# "test05@163.com",
# "test05", "ebd36739-0272-4b3f-95ab-0c6ac1639831", "", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNzg5OWUzOGQtNzczOS00NGNmLTgyODItZmFlMGZhNDJlZDYwIiwiZXhwIjoxNzMzNzI5NjQyLCJpc3MiOiJTRUxGX0hPU1RFRCIsInN1YiI6IkNvbnNvbGUgQVBJIFBhc3Nwb3J0In0.YMvypPnrvvUIfqzcESj820nP46IsFdTpF_YPz8_Exso")
- b = await a.invite_member_activate(
- "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMDE2NTcxNjAtZTllYi00NzVhLWIzMzYtZjlmZWJlY2I5YjczIiwiZXhwIjoxNzMzNzM0ODE0LCJpc3MiOiJTRUxGX0hPU1RFRCIsInN1YiI6IkNvbnNvbGUgQVBJIFBhc3Nwb3J0In0.khaXX3ndDe_pccEHcyTUcO2sgBCEfXCR74ZniP_b54Y",
- "zhao1@df.com",
- "zhao1Q",
- "ZHAOQG123456")
+ # b = await a.invite_member_activate(
+ # "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMDE2NTcxNjAtZTllYi00NzVhLWIzMzYtZjlmZWJlY2I5YjczIiwiZXhwIjoxNzMzNzM0ODE0LCJpc3MiOiJTRUxGX0hPU1RFRCIsInN1YiI6IkNvbnNvbGUgQVBJIFBhc3Nwb3J0In0.khaXX3ndDe_pccEHcyTUcO2sgBCEfXCR74ZniP_b54Y",
+ # "zhao1@df.com",
+ # "zhao1Q",
+ # "ZHAOQG123456")
print(b)
import asyncio
--
Gitblit v1.8.0