feat(backend): knowledge iteration + vision + neo4j + response contract source

dependencies.py 拆分为 dependencies/ 包; 新增 vision/ragflow_ingestion/neo4j 客户端与 h5_ai_task; alembic 045 图置信度迁移; 响应契约统一收尾。
This commit is contained in:
Simon
2026-07-09 11:47:16 +08:00
parent f5374fce9b
commit ead5f83bee
39 changed files with 5276 additions and 545 deletions
+42 -77
View File
@@ -1,95 +1,60 @@
# =============================================================================
# 企微IT智能服务台 — 阶段5 自动化 外部客户端工厂
# 企微IT智能服务台 — 外部系统集成 客户端工厂
# =============================================================================
# 说明:集中解析各外部系统的配置来源:
# - 优先使用 settings 中的 AUTOMATION_* 环境变量(架构约定)
# - 缺失时回退到既有 system_configs 表配置
# huorong/lianruan/ragflow 在 app/integrations/*/config.py 中已有 getter
# 说明:自动化引擎服务层(app.services.automation.*)统一从此处构建外部客户端。
#
# 为什么有工厂:自动化引擎既能用新加的 AUTOMATION_* 配置,也能复用阶段1-4
# 已落地的集成配置,避免重复维护两套配置源
# 设计:
# - 所有构建函数均为 coroutine,返回客户端实例或 None(未配置时)
# - 底层客户端来自 app.core.clients.*(环境变量 AUTOMATION_* 驱动),
# 与 app/integrations/{huorong,lianruan,ragflow}(管理后台 DB 配置)区分,
# 避免相互干扰。
# - 返回 None 时,引擎自动降级(关键词兜底 / EHR 兜底 / 转人工)。
#
# 调用约定(保持与现有服务层一致):
# build_huorong_client(db, audit) / build_lianruan_client(db, audit)
# build_dify_client(audit) / build_ehr_client(audit) / build_ragflow_client(audit)
# =============================================================================
from __future__ import annotations
import logging
from typing import Any, Callable, Optional
from typing import Any, Optional
from sqlalchemy.ext.asyncio import AsyncSession
from app.config import settings
logger = logging.getLogger(__name__)
from app.core.clients.dify import get_dify_client
from app.core.clients.ehr import get_ehr_client
from app.core.clients.huorong import get_huorong_client
from app.core.clients.lianruan import get_lianruan_client
from app.core.clients.ragflow import get_ragflow_client
async def build_huorong_client(
db: AsyncSession, audit: Optional[Callable[..., Any]] = None
):
"""构建火绒客户端:settings 优先,否则 system_configs。"""
from app.integrations.huorong.client import HuorongClient
if (
settings.automation_huorong_base_url
and settings.automation_huorong_access_key_id
and settings.automation_huorong_access_key_secret
):
return HuorongClient(
access_key_id=settings.automation_huorong_access_key_id,
access_key_secret=settings.automation_huorong_access_key_secret,
base_url=settings.automation_huorong_base_url,
)
from app.integrations.huorong.config import get_huorong_client
return await get_huorong_client(db)
async def build_huorong_client(db: Any = None, audit: Any = None) -> Optional[Any]:
"""构建火绒客户端(未配置返回 None)。"""
return await get_huorong_client(audit=audit)
async def build_lianruan_client(
db: AsyncSession, audit: Optional[Callable[..., Any]] = None
):
"""构建联软客户端:settings 优先,否则 system_configs。"""
from app.integrations.lianruan.client import LianruanClient
if (
settings.automation_lianruan_base_url
and settings.automation_lianruan_api_account
and settings.automation_lianruan_api_password
):
return LianruanClient(
base_url=settings.automation_lianruan_base_url,
api_account=settings.automation_lianruan_api_account,
api_password=settings.automation_lianruan_api_password,
validate_key=settings.automation_lianruan_validate_key,
)
from app.integrations.lianruan.config import get_lianruan_client
return await get_lianruan_client(db)
async def build_lianruan_client(db: Any = None, audit: Any = None) -> Optional[Any]:
"""构建联软客户端(未配置返回 None)。"""
return await get_lianruan_client(db=db, audit=audit)
async def build_ragflow_client(
db: AsyncSession, audit: Optional[Callable[..., Any]] = None
):
"""构建 RAGFlow 客户端:settings 优先,否则 system_configs。"""
from app.integrations.ragflow.client import RagflowClient
if settings.automation_ragflow_base_url and settings.automation_ragflow_api_key:
return RagflowClient(
api_key=settings.automation_ragflow_api_key,
base_url=settings.automation_ragflow_base_url,
)
from app.integrations.ragflow.config import get_ragflow_client
return await get_ragflow_client(db)
async def build_dify_client(audit: Optional[Callable[..., Any]] = None):
"""构建 Dify 客户端(仅 settings)。"""
from app.integrations.dify import get_dify_client
async def build_dify_client(audit: Any = None) -> Optional[Any]:
"""构建 Dify 意图识别客户端(未配置返回 None)。"""
return await get_dify_client(audit=audit)
async def build_ehr_client(audit: Optional[Callable[..., Any]] = None):
"""构建 EHR 客户端(仅 settings)。"""
from app.integrations.ehr import get_ehr_client
async def build_ehr_client(audit: Any = None) -> Optional[Any]:
"""构建北森 EHR 兜底客户端(未配置返回 None)。"""
return await get_ehr_client(audit=audit)
async def build_ragflow_client(audit: Any = None) -> Optional[Any]:
"""构建 RAGFlow 知识检索客户端(未配置返回 None)。"""
return await get_ragflow_client(audit=audit)
__all__ = [
"build_huorong_client",
"build_lianruan_client",
"build_dify_client",
"build_ehr_client",
"build_ragflow_client",
]