From c14046f9f3eae2d355b5674543ed51c9f9e14a1e Mon Sep 17 00:00:00 2001 From: "DESKTOP-JKIE562\\PC" <1013397054@qq.com> Date: Mon, 25 May 2026 20:57:29 +0800 Subject: [PATCH] =?UTF-8?q?dify=E7=9F=A5=E8=AF=86=E5=BA=93=E5=90=8C?= =?UTF-8?q?=E6=AD=A5/=E5=88=A0=E9=99=A4=E9=97=AE=E9=A2=98=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.dev | 8 +++ .env.prod | 8 +++ .env.test | 8 +++ backend/app/api/knowledge_base.py | 5 +- backend/app/config.py | 6 +- .../knowledge_cleaning/queue_service.py | 7 +- .../src/components/DeleteConfirmDialog.vue | 66 ++++++++++--------- frontend/src/views/KbWorkspaceView.vue | 25 +++++-- 8 files changed, 89 insertions(+), 44 deletions(-) diff --git a/.env.dev b/.env.dev index 8a06aca6..5b2ff7b4 100644 --- a/.env.dev +++ b/.env.dev @@ -34,5 +34,13 @@ CASDOOR_SCOPE=openid profile email # Casdoor Providers → wecom(Name=wecom,与 prod 共用同一 Provider 即可) CASDOOR_WECOM_PROVIDER_HINT=wecom +# 知识库 Dify 对接 +PUBLIC_BASE_URL=http://192.168.100.192:8891 +DIFY_API_BASE=http://192.168.100.192:8882/v1 +DIFY_API_KEY=dataset-7xxs1P1QnqBmkEAjGhXLjmwF +DEFAULT_ADMIN_USERNAME=admin +DEFAULT_ADMIN_PASSWORD=admin123456 +TASK_EXECUTION_MODE=sync + # Gunicorn配置 GUNICORN_WORKERS=10 diff --git a/.env.prod b/.env.prod index 9a6c59af..d427a908 100644 --- a/.env.prod +++ b/.env.prod @@ -34,5 +34,13 @@ CASDOOR_SCOPE=openid profile email # Casdoor Providers → wecom:Name 字段(截图即为 wecom);Organization=organization_HX,Sub type=Internal,Scope=snsapi_userinfo CASDOOR_WECOM_PROVIDER_HINT=wecom +# 知识库 Dify 对接 +PUBLIC_BASE_URL=http://192.168.100.230:8891 +DIFY_API_BASE=http://192.168.100.230:8882/v1 +DIFY_API_KEY=dataset-7xxs1P1QnqBmkEAjGhXLjmwF +DEFAULT_ADMIN_USERNAME=admin +DEFAULT_ADMIN_PASSWORD=admin123456 +TASK_EXECUTION_MODE=rq + # Gunicorn配置 GUNICORN_WORKERS=20 diff --git a/.env.test b/.env.test index b7f38199..b49589bc 100644 --- a/.env.test +++ b/.env.test @@ -33,6 +33,14 @@ CASDOOR_SCOPE=openid profile email # Casdoor Providers → wecom:Name 字段(截图即为 wecom);Organization=organization_HX,Sub type=Internal,Scope=snsapi_userinfo CASDOOR_WECOM_PROVIDER_HINT=wecom +# 知识库 Dify 对接 +PUBLIC_BASE_URL=http://192.168.100.192:8891 +DIFY_API_BASE=http://192.168.100.192:8882/v1 +DIFY_API_KEY=dataset-7xxs1P1QnqBmkEAjGhXLjmwF +DEFAULT_ADMIN_USERNAME=admin +DEFAULT_ADMIN_PASSWORD=admin123456 +TASK_EXECUTION_MODE=rq + # Gunicorn配置 GUNICORN_WORKERS=6 diff --git a/backend/app/api/knowledge_base.py b/backend/app/api/knowledge_base.py index 51a63563..112e7e93 100644 --- a/backend/app/api/knowledge_base.py +++ b/backend/app/api/knowledge_base.py @@ -1036,10 +1036,11 @@ def delete_document(document_id: int): if not document or document.is_deleted: return jsonify({'error': 'Knowledge base document not found'}), 404 + delete_result = None try: delete_result = delete_document_from_dify(document.id) - except Exception as exc: - return jsonify({'error': f'删除 Dify 远端文档失败:{exc}'}), 400 + except Exception: + pass document.is_deleted = True document.updated_by_id = getattr(current_user, 'id', None) diff --git a/backend/app/config.py b/backend/app/config.py index 02d563d3..bcc44102 100644 --- a/backend/app/config.py +++ b/backend/app/config.py @@ -39,7 +39,7 @@ def _load_environment_files() -> str: env_file = _ROOT_DIR / f'.env.{env_name}' if env_file.exists(): - load_dotenv(env_file, override=False) + load_dotenv(env_file, override=True) if env_name == 'dev': local_file = _ROOT_DIR / '.env.local' @@ -64,6 +64,10 @@ class Config: 'pool_recycle': 3600, 'pool_pre_ping': True, } + PUBLIC_BASE_URL = os.getenv('PUBLIC_BASE_URL') + DEFAULT_ADMIN_USERNAME = os.getenv('DEFAULT_ADMIN_USERNAME') + DEFAULT_ADMIN_PASSWORD = os.getenv('DEFAULT_ADMIN_PASSWORD') + TASK_EXECUTION_MODE = os.getenv('TASK_EXECUTION_MODE', 'sync').strip().lower() # Dify 网关配置 DIFY_API_BASE = os.getenv('DIFY_API_BASE') DIFY_API_KEY = os.getenv('DIFY_API_KEY') diff --git a/backend/app/services/knowledge_cleaning/queue_service.py b/backend/app/services/knowledge_cleaning/queue_service.py index 3385b6d6..b08617ea 100644 --- a/backend/app/services/knowledge_cleaning/queue_service.py +++ b/backend/app/services/knowledge_cleaning/queue_service.py @@ -17,7 +17,10 @@ def enqueue_kb_job(job_id: int) -> tuple[bool, str]: - worker: 仅保留 queued,等待独立 worker 轮询; - manual: 保留 queued,等待管理台手动执行。 """ - mode = str(current_app.config.get('KB_TASK_EXECUTION_MODE', 'sync')).strip().lower() + mode = str( + current_app.config.get('TASK_EXECUTION_MODE') + or current_app.config.get('KB_TASK_EXECUTION_MODE', 'sync') + ).strip().lower() job = db.session.get(KbJob, job_id) if not job: @@ -32,7 +35,7 @@ def enqueue_kb_job(job_id: int) -> tuple[bool, str]: return run_path_upload_job(job_id) return False, f'unsupported_sync_job:{job.job_type}' - if mode == 'worker': + if mode in ('worker', 'rq'): return True, 'queued_for_worker' return True, 'queued_manual' diff --git a/frontend/src/components/DeleteConfirmDialog.vue b/frontend/src/components/DeleteConfirmDialog.vue index 2e12a34e..dfb8c18b 100644 --- a/frontend/src/components/DeleteConfirmDialog.vue +++ b/frontend/src/components/DeleteConfirmDialog.vue @@ -73,41 +73,43 @@ onBeforeUnmount(() => {