From 345f2822f5072c34d9f969ae077830af968043b9 Mon Sep 17 00:00:00 2001 From: zhaoqingang <zhaoqg0118@163.com> Date: 星期四, 27 二月 2025 11:44:31 +0800 Subject: [PATCH] 优化输出 --- app/service/v2/chat.py | 10 ++++++++-- app/init_config/init_run_data.py | 2 ++ app/api/system.py | 2 +- app/service/system.py | 3 ++- app/api/chat.py | 4 ++-- app/config/env_conf/config.yaml | 12 ++++++------ main.py | 1 - app/config/env_conf/admin.yaml | 10 +++++----- 8 files changed, 26 insertions(+), 18 deletions(-) diff --git a/app/api/chat.py b/app/api/chat.py index 241815a..16003e2 100644 --- a/app/api/chat.py +++ b/app/api/chat.py @@ -325,7 +325,7 @@ # token = get_dify_token(db, current_user.id) try: async def forward_to_dify(): - if agent.type == "imageTalk": + if chat_type == "imageTalk": token = DfTokenDao(db).get_token_by_id(IMAGE_TO_TEXT) if not token: await websocket.send_json({"message": "Invalid token", "type": "error"}) @@ -431,7 +431,7 @@ result = {"message": f"鍐呴儴閿欒锛� {e2}", "type": "close"} await websocket.send_json(result) print(f"Error process message of ragflow: {e2}") - elif agent.type == "reportWorkflow": + elif chat_type == "reportWorkflow": while True: receive_message = await websocket.receive_json() diff --git a/app/api/system.py b/app/api/system.py index c9f237b..72c9cec 100644 --- a/app/api/system.py +++ b/app/api/system.py @@ -12,7 +12,7 @@ @system_router.get("/info", response_model=Response) -async def api_get_system_data(current_user: UserModel = Depends(get_current_user), db=Depends(get_db)): +async def api_get_system_data(db=Depends(get_db)): data = await services_get_system_data(db) return Response(code=200, msg="successfully", data=data) diff --git a/app/config/env_conf/admin.yaml b/app/config/env_conf/admin.yaml index 7c12711..30ad3bf 100644 --- a/app/config/env_conf/admin.yaml +++ b/app/config/env_conf/admin.yaml @@ -3,10 +3,10 @@ password: gAAAAABnvAq8bErFiR9x_ZcODjUeOdrDo8Z5UVOzyqo6SxIhAvLpw81kciQN0frwIFVfY9wrxH1WqrpTICpEwfH7r2SkLjS7SQ== chat_server: - id: 2c039666c29d11efa4670242ac1b0006 - account: zhao1@example.com - password: gAAAAABnpFLtotY2OIRH12BJh4MzMgn5Zil7-DVpIeuqlFwvr0g6g_n4ULogn-LNhCbtk6cCDkzZlqAHvBSX2e_zf7AsoyzbiQ== + id: fe24dd2c9be611ef92880242ac160006 + account: user@example.com + password: gAAAAABnvs3e3fZOYfUUAJ6uT80dkhNeN7rhylzZErTWRZThNSLzMbZGetPCe9A2BJ86V0nZBLMNNu8w6rWp4dC7JxYxByJcow== workflow_server: - account: admin@basic.com - password: gAAAAABnpFLtotY2OIRH12BJh4MzMgn5Zil7-DVpIeuqlFwvr0g6g_n4ULogn-LNhCbtk6cCDkzZlqAHvBSX2e_zf7AsoyzbiQ== \ No newline at end of file + account: basic@mail.com + password: gAAAAABnvs5i7xUn9pb2szCozJciGSiWPGv80PH_2HFFzNM2r1ZLTOQqftnUso_bvchtmwAmccfNrf53sf9_WMFVTc0hjTKRRQ== \ No newline at end of file diff --git a/app/config/env_conf/config.yaml b/app/config/env_conf/config.yaml index 30d2988..3f9217f 100644 --- a/app/config/env_conf/config.yaml +++ b/app/config/env_conf/config.yaml @@ -1,10 +1,10 @@ secret_key: your-secret-key sgb_base_url: http://192.168.20.119:13001 sgb_websocket_url: ws://192.168.20.119:13001 -fwr_base_url: http://192.168.20.116:11080 -database_url: mysql+pymysql://root:infini_rag_flow@192.168.20.119:5455/rag_basic +fwr_base_url: http://192.168.20.119:11080 +database_url: mysql+pymysql://root:rag_gateway@192.168.20.116:23306/rag_gateway sgb_db_url: mysql+pymysql://root:1234@192.168.20.119:13306/bisheng -fwr_db_url: mysql+pymysql://root:infini_rag_flow@192.168.20.116:15455/rag_flow +fwr_db_url: mysql+pymysql://root:infini_rag_flow@192.168.20.119:15455/rag_flow PUBLIC_KEY: | -----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArq9XTUSeYr2+N1h3Afl/z8Dse/2yD0ZGrKwx+EEEcdsBLca9Ynmx3nIB5obmLlSfmskLpBo0UACBmB5rEjBp2Q2f3AG3Hjd4B+gNCG6BDaawuDlgANIhGnaTLrIqWrrcm4EMzJOnAOI1fgzJRsOOUEfaS318Eq9OVO3apEyCCt0lOQK6PuksduOjVxtltDav+guVAA068NrPYmRNabVKRNLJpL8w4D44sfth5RvZ3q9t+6RTArpEtc5sh5ChzvqPOzKGMXW83C95TxmXqpbK6olN4RevSfVjEAgCydH6HN6OhtOQEcnrU97r9H0iZOWwbw3pVrZiUkuRD1R56Wzs2wIDAQAB @@ -15,11 +15,11 @@ PASSWORD_KEY: VKinqB-8XMrwCLLrcf_PyHyo12_4PVKvWzaHjNFions= basic_base_url: http://192.168.20.231:8000 basic_paper_url: http://192.168.20.231:8000 -dify_base_url: http://192.168.20.119:13002 +dify_base_url: http://192.168.20.116 dify_api_token: app-YmOAMDsPpDDlqryMHnc9TzTO -postgresql_database_url: postgresql+asyncpg://kong:kongpass@192.168.20.119:5432/kong +postgresql_database_url: postgresql+asyncpg://kong:kongpass@192.168.20.116:15433/kong dify_workflow_clean: app-OpF0drPu0XcgqcekQpT4FA8a dify_workflow_report: app-0MAkdFWqh9zxwmU69O0BFU1s -dify_database_url: postgresql+psycopg2://postgres:difyai123456@192.168.20.119:15432/dify +dify_database_url: postgresql+psycopg2://postgres:difyai123456@192.168.20.116:15432/dify diff --git a/app/init_config/init_run_data.py b/app/init_config/init_run_data.py index 208433f..db095fb 100644 --- a/app/init_config/init_run_data.py +++ b/app/init_config/init_run_data.py @@ -1,6 +1,7 @@ from app.models.base_model import SessionLocal from app.service.v2.initialize_data import dialog_menu_sync, default_group_sync, default_role_sync, \ basic_agent_sync, admin_account_sync, sync_rg_api_token +from app.task.sync_account_token import sync_token async def sync_default_data(): @@ -13,6 +14,7 @@ await basic_agent_sync(db) # 寮�鍙戠殑agent await admin_account_sync(db) # await sync_rg_api_token(db) # + await sync_token() # 鍚姩鍚屾token浠诲姟 except Exception as e: print(e) diff --git a/app/service/system.py b/app/service/system.py index 23309f9..4df1e03 100644 --- a/app/service/system.py +++ b/app/service/system.py @@ -27,7 +27,8 @@ async def services_update_system_data(db, title, desc, logo): try: - shutil.move(os.path.join(APP_STATIC_PATH, logo), os.path.join(APP_STATIC_PATH, "logo.png")) + if os.path.exists(os.path.join(APP_STATIC_PATH, logo)): + shutil.move(os.path.join(APP_STATIC_PATH, logo), os.path.join(APP_STATIC_PATH, "logo.png")) system = db.query(SystemDataModel).filter_by(id=SYSTEM_ID).first() system.title = title system.desc = desc diff --git a/app/service/v2/chat.py b/app/service/v2/chat.py index a35c775..a24f88d 100644 --- a/app/service/v2/chat.py +++ b/app/service/v2/chat.py @@ -169,7 +169,7 @@ query = chat_data.query else: query = "start new workflow" - session = await add_session_log(db, session_id, query, chat_id, user_id, mode, conversation_id, 3) + session = await add_session_log(db, session_id,query if query else "start new conversation", chat_id, user_id, mode, conversation_id, 3) if session: conversation_id = session.conversation_id try: @@ -205,6 +205,9 @@ data["outputs"] = await data_process(data.get("outputs", {})) data["files"] = await data_process(data.get("files", [])) data["process_data"] = "" + if data.get("status") == "failed": + status = http_500 + error = data.get("error", "") node_list.append(ans) event = [smart_workflow_started, smart_node_started, smart_node_finished][ [workflow_started, node_started, node_finished].index(ans.get("event"))] @@ -213,6 +216,9 @@ answer_workflow = data.get("outputs", {}).get("output") download_url = data.get("outputs", {}).get("download_url") event = smart_workflow_finished + if data.get("status") == "failed": + status = http_500 + error = data.get("error", "") node_list.append(ans) elif ans.get("event") == message_end: @@ -234,7 +240,7 @@ except: ... finally: - await update_session_log(db, session_id, {"role": "assistant", "answer": answer_event or answer_agent or answer_workflow, + await update_session_log(db, session_id, {"role": "assistant", "answer": answer_event or answer_agent or answer_workflow or error, "download_url":download_url, "node_list": node_list, "task_id": task_id, "id": message_id, "error": error}, conversation_id) diff --git a/main.py b/main.py index 20cd8fe..05494b9 100644 --- a/main.py +++ b/main.py @@ -48,7 +48,6 @@ sync_agents_v2() # 鏅鸿兘浣� sync_knowledge() # 鐭ヨ瘑搴� sync_resources_from_json() - await sync_token() # 鍚姩鍚屾token浠诲姟 yield # 鍦ㄥ簲鐢ㄥ叧闂椂鎵ц娓呯悊鎿嶄綔锛堝鏋滈渶瑕侊級 pass -- Gitblit v1.8.0