From 0078ac6ffa486c481c26b7c0b033ff9664096a7f Mon Sep 17 00:00:00 2001 From: zhaoqingang <zhaoqg0118@163.com> Date: 星期二, 11 二月 2025 16:38:10 +0800 Subject: [PATCH] 报告生成增加 --- app/init_config/init_run_data.py | 18 ++- menu_conf.json | 169 +++++++++++++++++++++++++++++++++ app/config/env_conf/admin.yaml | 12 ++ app/api/files.py | 2 app/service/v2/initialize_data.py | 43 ++++++++ app/config/env_conf/menu_conf.json | 12 + 6 files changed, 245 insertions(+), 11 deletions(-) diff --git a/app/api/files.py b/app/api/files.py index c9f0524..db8936b 100644 --- a/app/api/files.py +++ b/app/api/files.py @@ -118,7 +118,7 @@ raise HTTPException(status_code=500, detail=str(e)) elif agent.chat_type == "reportWorkflow" or agent.chat_type == "documentIa" or agent.chat_type == "paperTalk": token_dict = { - "reportWorkflow": DOCUMENT_TO_REPORT, + "reportWorkflow": DOCUMENT_TO_REPORT_TITLE, "documentIa": DOCUMENT_IA_QUESTIONS, "paperTalk": DOCUMENT_TO_PAPER, } diff --git a/app/config/env_conf/admin.yaml b/app/config/env_conf/admin.yaml new file mode 100644 index 0000000..3821bfd --- /dev/null +++ b/app/config/env_conf/admin.yaml @@ -0,0 +1,12 @@ +smart_server: + account: administer + password: basic@2025 + +ragflow_app: + id: 2c039666c29d11efa4670242ac1b0006 + account: admin@example.com + password: basic@2025 + +dify_app: + account: admin@mail.com + password: basic@2025 \ No newline at end of file diff --git a/app/config/env_conf/menu_conf.json b/app/config/env_conf/menu_conf.json index 13715d0..b35dbfc 100644 --- a/app/config/env_conf/menu_conf.json +++ b/app/config/env_conf/menu_conf.json @@ -138,7 +138,7 @@ }, { "id": 9, - "title": "", + "title": "鎶ュ憡鐢熸垚", "icon": "2", "img": "/src/assets/index/2.png", "desc": "鍩轰簬鎮ㄥ垱寤虹殑鎶ュ憡鏍煎紡鍜屼笂浼犵殑鏂囨。鍐呭锛屽揩閫熺敓鎴愬畾鍒舵姤鍛婏紝骞舵敮鎸佷竴閿笅杞姐��", @@ -146,13 +146,19 @@ "rank": 91, "dialog": [ { - "id": "72a69e47-458d-47f9-b534-1859e5da244f", + "id": "87b8e17c-594d-424f-b9f8-0b56036904c9", "chat_id": "basic_report_clean", "chat_type": "reportWorkflow", "agentType": 4 }, { - "id": "6eda0700-6273-488d-a97c-88d315bd9d8f", + "id": "61d26deb-9371-4f9c-b61b-b9f9a24a9188", + "chat_id": "basic_report_clean", + "chat_type": "reportWorkflow", + "agentType": 4 + }, + { + "id": "d6eea92d-444a-4658-b9e7-9ab7bd5cb19d", "chat_id": "basic_report_clean", "chat_type": "reportWorkflow", "agentType": 4 diff --git a/app/init_config/init_run_data.py b/app/init_config/init_run_data.py index 76ef2db..98e6a44 100644 --- a/app/init_config/init_run_data.py +++ b/app/init_config/init_run_data.py @@ -1,15 +1,21 @@ from app.models.base_model import SessionLocal from app.service.v2.initialize_data import dialog_menu_sync, default_group_sync, default_role_sync, app_register_sync, \ - basic_agent_sync + basic_agent_sync, admin_user_sync async def sync_default_data(): db = SessionLocal() - await dialog_menu_sync(db) # 灏忔暟 - await default_group_sync(db) # 榛樿缁� - await default_role_sync(db) # 榛樿瑙掕壊 - await app_register_sync(db) # 娉ㄥ唽鐨勫簲鐢� - await basic_agent_sync(db) # 寮�鍙戠殑agent + try: + await dialog_menu_sync(db) # 灏忔暟 + await default_group_sync(db) # 榛樿缁� + await default_role_sync(db) # 榛樿瑙掕壊 + await app_register_sync(db) # 娉ㄥ唽鐨勫簲鐢� + await basic_agent_sync(db) # 寮�鍙戠殑agent + await admin_user_sync(db) # 寮�鍙戠殑agent + except Exception as e: + print(e) + finally: + db.close() # await default_role_sync(db) # 椤甸潰璧勬簮閰嶇疆淇℃伅 # await default_role_sync(db) # 榛樿鐨勮鑹茶祫婧� diff --git a/app/service/v2/initialize_data.py b/app/service/v2/initialize_data.py index d6df64b..512a2d3 100644 --- a/app/service/v2/initialize_data.py +++ b/app/service/v2/initialize_data.py @@ -1,8 +1,13 @@ import json import time import os + +import yaml +from passlib.context import CryptContext + from Log import logger -from app.config.const import DIFY, ENV_CONF_PATH +# from app.api import pwd_context +from app.config.const import DIFY, ENV_CONF_PATH, RAGFLOW from app.models import MenuCapacityModel, WebMenuModel, GroupModel, RoleModel, DialogModel, UserModel, UserAppModel, \ cipher_suite from app.service.auth import UserAppDao @@ -13,6 +18,8 @@ from app.service.v2.app_register import AppRegisterDao from app.config.config import settings from app.utils.password_handle import generate_password + +pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") async def dialog_menu_sync(db): @@ -219,3 +226,37 @@ if not user_id: raise Exception("Failed to register with app") print({"msg": "User registered successfully", "userFlag": user_id}) + + +async def admin_user_sync(db): + try: + config = {} + with open(os.path.join(ENV_CONF_PATH, "admin.yaml"), 'r', encoding='utf-8') as file: + # 鍔犺浇JSON鏁版嵁 + config = yaml.safe_load(file) + # print(config) + db_user = db.query(UserModel).filter(UserModel.username == config["smart_server"]["account"]).first() + if db_user: + print("admin_user_sync: 鐢ㄦ埛宸茬粡瀛樺湪锛�") + return + register_dict = {} + + for app in [RAGFLOW, DIFY]: + register_dict[app] = {"id": config[app].get("id", "123"), "name": config[app]["account"], + "pwd":config[app]["password"], + "email": config[app]["account"]} + + # 瀛樺偍鐢ㄦ埛淇℃伅 + hashed_password = pwd_context.hash(config["smart_server"]["password"]) + user_model = UserModel(username=config["smart_server"]["account"], hashed_password=hashed_password, email="", + phone="", login_name="", sync_flag="", creator=0, permission="admin") + db.add(user_model) + db.commit() + db.refresh(user_model) + u_id = user_model.id + user_app_dao = UserAppDao(db) + for k, v in register_dict.items(): + await user_app_dao.update_and_insert_data(v.get("name"), user_model.encrypted_password(v.get("pwd")), v.get("email"), u_id, str(v.get("id")), k) + except Exception as e: + print(e) + db.rollback() \ No newline at end of file diff --git a/menu_conf.json b/menu_conf.json new file mode 100644 index 0000000..b35dbfc --- /dev/null +++ b/menu_conf.json @@ -0,0 +1,169 @@ +{ + "data": [ + { + "id": 1, + "title": "鎶ヨ〃鍚堝苟", + "icon": "6", + "img": "/src/assets/index/6.png", + "desc": "鍩轰簬鎮ㄤ笂浼犵殑鎶ヨ〃杩涜鍚堝苟锛屽姪鎮ㄥ揩閫熷畬鎴愭姤琛ㄦ暣鍚堜笌鍒嗘瀽", + "describe": "鍩轰簬鎮ㄤ笂浼犵殑鎶ヨ〃杩涜鍚堝苟锛屽姪鎮ㄥ揩閫熷畬鎴愭姤琛ㄦ暣鍚堜笌鍒嗘瀽", + "dialog": [ + { + "id": "basic_excel_merge", + "chat_id": "basic_excel_merge", + "chat_type": "excelMerge", + "agentType": 3 + } + ], + "rank": 99 + }, + { + "id": 2, + "title": "鐭ヨ瘑闂瓟", + "icon": "5", + "img": "/src/assets/index/5.png", + "desc": "閬嶅巻宸插垱寤虹殑鏂囨。鐭ヨ瘑搴擄紝鐢熸垚瀹屾暣鍜屽噯纭殑绛旀锛屽悓鏃舵樉绀烘潵婧愭枃妗d緵鎮ㄥ弬鑰�", + "describe": "鍨傚煙鐭ヨ瘑鐨勯棶绛斿姪鎵嬶紝閽堝浣犵殑鎻愰棶锛屾垜浠皢閬嶅巻宸插垱寤虹殑鏂囨。鐭ヨ瘑搴擄紝鐢熸垚瀹屾暣鍜屽噯纭殑绛旀锛屽悓鏃舵樉绀烘潵婧愭枃妗d緵鎮ㄥ弬鑰冦��", + "rank": 105, + "dialog": [ + { + "id": "e476db7cbdbb11ef82b50242ac130006", + "chat_id": "e476db7cbdbb11ef82b50242ac130006", + "chat_type": "knowledgeQA", + "agentType": 1 + } + ] + }, + { + "id": 3, + "title": "鏂囨。鏅鸿兘", + "icon": "7", + "img": "/src/assets/index/7.png", + "desc": "涓汉鐭ヨ瘑搴撶殑闂瓟鍔╂墜锛屽熀浜庢偍涓婁紶鐨勬枃妗h繘琛岄棶绛旓紝鏀寔澶氭枃妗�", + "describe": "涓汉鐭ヨ瘑搴撶殑闂瓟鍔╂墜锛屽熀浜庢偍涓婁紶鐨勬枃妗h繘琛岄棶绛旓紝鏀寔澶氭枃妗o紝澶у皬鍦�30M浠ュ唴銆�", + "rank": 97, + "dialog": [ + { + "id": "7638f006-38a2-4c21-a68e-c6c49b304a35", + "chat_id": "7638f006-38a2-4c21-a68e-c6c49b304a35", + "chat_type": "documentIa", + "agentType": 4 + } + ] + }, + { + "id": 4, + "title": "鏅鸿兘闂瓟", + "icon": "1", + "img": "/src/assets/index/1.png", + "desc": "鑳藉鐞嗚В鍜屽涔犱汉绫荤殑璇█锛屽叿澶囧杞璇濈殑鑳藉姏", + "describe": "鎴戝彲浠ョ悊瑙e拰瀛︿範浜虹被鐨勮瑷�锛屽叿澶囧杞璇濈殑鑳藉姏锛岀幇鍦ㄥ拰鎴戝紑濮嬩氦娴佸惂锝�", + "rank": 104, + "dialog": [ + { + "id": "90d533729c0211efbf6b0242ac160006", + "chat_id": "90d533729c0211efbf6b0242ac160006", + "chat_type": "chat", + "agentType": 1 + } + ] + }, + { + "id": 5, + "title": "鏅鸿兘鏁版嵁", + "icon": "8", + "img": "/src/assets/index/8.png", + "desc": "鎮ㄥ彲浠ヤ笂浼犳枃妗f垨娣诲姞鏁版嵁搴撳湴鍧�锛屽皬鏁板彲閽堝浣犳枃妗g殑鏁版嵁杩涜鍒嗘瀽锛屽苟鐢熸垚鎸囧畾鐨勫浘琛�", + "describe": "鎮ㄥ彲浠ヤ笂浼犳枃妗f垨娣诲姞鏁版嵁搴撳湴鍧�锛屽皬鏁板彲閽堝浣犳枃妗g殑鏁版嵁杩涜鍒嗘瀽锛屽苟鐢熸垚鎸囧畾鐨勫浘琛�", + "rank": 95, + "dialog": [ + { + "id": "basic_excel_talk", + "chat_id": "basic_excel_talk", + "chat_type": "excelTalk", + "agentType": 3 + } + ] + }, + { + "id": 6, + "title": "灏忔暟缁樺浘", + "icon": "7", + "img": "/src/assets/index/7.png", + "desc": "鍩轰簬鎮ㄤ笂浼犵殑鍥剧墖锛岀敓鎴愬搴旂殑鏂囧瓧鎻忚堪骞跺熀浜庡浘鐗囧唴瀹瑰疄鐜伴棶绛斻��", + "describe": "鍩轰簬鎮ㄤ笂浼犵殑鍥剧墖锛岀敓鎴愬搴旂殑鏂囧瓧鎻忚堪骞跺熀浜庡浘鐗囧唴瀹瑰疄鐜伴棶绛斻��", + "rank": 94, + "dialog": [ + { + "id": "9d75142a-66eb-4e23-b7d4-03efe4584915", + "chat_id": "9d75142a-66eb-4e23-b7d4-03efe4584915", + "chat_type": "imageTalk", + "agentType": 4 + } + ] + }, + { + "id": 7, + "title": "鏂囨。鍑哄嵎", + "icon": "6", + "img": "/src/assets/index/6.png", + "desc": "鎮ㄥ彲浠ヤ笂浼犳枃妗o紝灏忔暟鑳介拡瀵瑰崟鏂囨。鎴栧涓枃妗e唴瀹硅嚜鍔ㄥ嚭棰橈紝楂樻晥渚挎嵎鐨勫府鍔╀綘寤虹珛绉佷汉棰樺簱銆�", + "describe": "鎮ㄥ彲浠ヤ笂浼犳枃妗o紝灏忔暟鑳介拡瀵瑰崟鏂囨。鎴栧涓枃妗e唴瀹硅嚜鍔ㄥ嚭棰橈紝楂樻晥渚挎嵎鐨勫府鍔╀綘寤虹珛绉佷汉棰樺簱銆�", + "rank": 93, + "dialog": [ + { + "id": "2f6ddf93-7ba6-4b2d-b991-d96421404600", + "chat_id": "2f6ddf93-7ba6-4b2d-b991-d96421404600", + "chat_type": "paperTalk", + "agentType": 4 + } + ] + }, + { + "id": 8, + "title": "鍑洪缁勫嵎", + "icon": "6", + "img": "/src/assets/index/6.png", + "desc": "鎮ㄥ彲浠ヤ笂浼犳枃妗o紝灏忔暟鑳介拡瀵瑰崟鏂囨。鎴栧涓枃妗e唴瀹硅嚜鍔ㄥ嚭棰橈紝楂樻晥渚挎嵎鐨勫府鍔╀綘寤虹珛绉佷汉棰樺簱銆�", + "describe": "鎮ㄥ彲浠ヤ笂浼犳枃妗o紝灏忔暟鑳介拡瀵瑰崟鏂囨。鎴栧涓枃妗e唴瀹硅嚜鍔ㄥ嚭棰橈紝楂樻晥渚挎嵎鐨勫府鍔╀綘寤虹珛绉佷汉棰樺簱銆�", + "rank": 92, + "dialog": [ + { + "id": "basic_question_talk", + "chat_id": "basic_question_talk", + "chat_type": "questionTalk", + "agentType": 3 + } + ] + }, + { + "id": 9, + "title": "鎶ュ憡鐢熸垚", + "icon": "2", + "img": "/src/assets/index/2.png", + "desc": "鍩轰簬鎮ㄥ垱寤虹殑鎶ュ憡鏍煎紡鍜屼笂浼犵殑鏂囨。鍐呭锛屽揩閫熺敓鎴愬畾鍒舵姤鍛婏紝骞舵敮鎸佷竴閿笅杞姐��", + "describe": "鍩轰簬鎮ㄥ垱寤虹殑鎶ュ憡鏍煎紡鍜屼笂浼犵殑鏂囨。鍐呭锛屽揩閫熺敓鎴愬畾鍒舵姤鍛婏紝骞舵敮鎸佷竴閿笅杞姐��", + "rank": 91, + "dialog": [ + { + "id": "87b8e17c-594d-424f-b9f8-0b56036904c9", + "chat_id": "basic_report_clean", + "chat_type": "reportWorkflow", + "agentType": 4 + }, + { + "id": "61d26deb-9371-4f9c-b61b-b9f9a24a9188", + "chat_id": "basic_report_clean", + "chat_type": "reportWorkflow", + "agentType": 4 + }, + { + "id": "d6eea92d-444a-4658-b9e7-9ab7bd5cb19d", + "chat_id": "basic_report_clean", + "chat_type": "reportWorkflow", + "agentType": 4 + } + ] + } + ] +} \ No newline at end of file -- Gitblit v1.8.0