perf(kb):知识库数据清洗同步改异步优化;chat中查假期请假agent入口优化

This commit is contained in:
runny committed 2026-06-05 23:55:38 +08:00
1 parent 61ebb46c0f
commit c3b63df2f5
11 files changed
+839 -171

No files matched your search

+20 -16
View File
@@ -25,6 +25,13 @@ from app.models import Agent, ChatLog, ChatSession, Feedback
from app import db
from app.errors import AppError, ValidationError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, ServiceUnavailableError, raise_for_status
chat_bp = Blueprint('chat', __name__)
LEAVE_FEATURE_AGENT_NAMES = {'通用入口', '人事规章'}
def _can_use_leave_feature(agent_proxy) -> bool:
agent_name = str(getattr(agent_proxy, 'name', None) or '').strip()
return agent_name in LEAVE_FEATURE_AGENT_NAMES
PLM_PREVIEW_SHARE_ROOT = (os.getenv('PLM_PREVIEW_SHARE_ROOT') or '\\\\192.168.0.11\\dss\\dssroot\\').strip()
def _session_title_from_text(text: str) -> str:
@@ -1056,27 +1063,24 @@ def chat_completions():
if normalized_files and PLMOracleService.supports(query, agent_proxy):
raise ValidationError('This route does not support attachments')
from app.services.hr_leave_sqlserver import HRLeaveSQLServerService
leave_supported = HRLeaveSQLServerService.supports(query)
leave_feature_enabled = _can_use_leave_feature(agent_proxy)
if PLMOracleService.supports(query, agent_proxy):
generator = PLMOracleService.stream_chat(query, user_proxy, agent_proxy, external_conversation_id, session_id=session.session_id)
elif leave_supported and leave_feature_enabled:
if normalized_files:
raise ValidationError('This route does not support attachments')
generator = HRLeaveSQLServerService.stream_chat(query, user_proxy, agent_proxy, external_conversation_id, session_id=session.session_id)
elif leave_supported:
generator = DifyService.stream_chat(query, user_proxy.id, agent_proxy, external_conversation_id, request_id=request_id, session_id=session.session_id, files=normalized_files)
elif kb_type == 'ERP知识库':
from app.services.hr_leave_sqlserver import HRLeaveSQLServerService
from app.services.text2sql import Text2SQLService
if HRLeaveSQLServerService.supports(query):
if normalized_files:
raise ValidationError('This route does not support attachments')
generator = HRLeaveSQLServerService.stream_chat(query, user_proxy, agent_proxy, external_conversation_id, session_id=session.session_id)
else:
if normalized_files:
raise ValidationError('This route does not support attachments')
generator = Text2SQLService.stream_chat(query, user_proxy.id, agent_proxy, external_conversation_id, session_id=session.session_id)
if normalized_files:
raise ValidationError('This route does not support attachments')
generator = Text2SQLService.stream_chat(query, user_proxy.id, agent_proxy, external_conversation_id, session_id=session.session_id)
else:
from app.services.hr_leave_sqlserver import HRLeaveSQLServerService
if HRLeaveSQLServerService.supports(query):
if normalized_files:
raise ValidationError('This route does not support attachments')
generator = HRLeaveSQLServerService.stream_chat(query, user_proxy, agent_proxy, external_conversation_id, session_id=session.session_id)
else:
generator = DifyService.stream_chat(query, user_proxy.id, agent_proxy, external_conversation_id, request_id=request_id, session_id=session.session_id, files=normalized_files)
generator = DifyService.stream_chat(query, user_proxy.id, agent_proxy, external_conversation_id, request_id=request_id, session_id=session.session_id, files=normalized_files)
def relay_stream():
created_event = {