Merge branch 'dev' into hugo
# Conflicts: # .env.dev # .env.shared # backend/app/api/chat.py
This commit is contained in:
commit
ee90b66ff7
63 files changed
+4786
-1422
No files matched your search
+31
-9
@@ -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:
|
||||
@@ -1079,20 +1086,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:
|
||||
<<<<<<< HEAD
|
||||
from app.services.hr_leave_sqlserver import HRLeaveSQLServerService
|
||||
if HRLeaveSQLServerService.supports(query):
|
||||
if normalized_files:
|
||||
@@ -1113,6 +1124,9 @@ def chat_completions():
|
||||
files=normalized_files,
|
||||
inputs=dify_inputs,
|
||||
)
|
||||
=======
|
||||
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)
|
||||
>>>>>>> dev
|
||||
|
||||
def relay_stream():
|
||||
created_event = {
|
||||
@@ -1705,6 +1719,10 @@ def preview_file_raw():
|
||||
content = _convert_office_to_pdf(content, ext)
|
||||
ext = 'pdf'
|
||||
content_type = 'application/pdf'
|
||||
if name and '.' in name:
|
||||
name = f"{name.rsplit('.', 1)[0]}.pdf"
|
||||
elif name:
|
||||
name = f"{name}.pdf"
|
||||
except Exception as e:
|
||||
current_app.logger.error("[file-preview] LibreOffice conversion failed: %s", e)
|
||||
placeholder_text = _extract_placeholder_text(content)
|
||||
@@ -1712,6 +1730,10 @@ def preview_file_raw():
|
||||
content = placeholder_text.encode('utf-8')
|
||||
ext = 'txt'
|
||||
content_type = 'text/plain; charset=utf-8'
|
||||
if name and '.' in name:
|
||||
name = f"{name.rsplit('.', 1)[0]}.txt"
|
||||
elif name:
|
||||
name = f"{name}.txt"
|
||||
current_app.logger.info('[file-preview] office preview degraded to text placeholder for %s', file_url)
|
||||
else:
|
||||
raise AppError(
|
||||
|
||||
Reference in new issue
Block a user