48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
"""
|
|
api/chat/shared.py
|
|
|
|
用途:汇总聊天 API 子模块共同使用的框架对象、模型、服务和常量。
|
|
依赖:Flask、SQLAlchemy、DifyService、IntegrationApiService、聊天数据模型。
|
|
逻辑:各 chat 路由模块从本文件复用基础依赖;Blueprint 仅由 api/chat/__init__.py 创建,避免重复注册。
|
|
"""
|
|
import io
|
|
import ipaddress
|
|
import mimetypes
|
|
import ntpath
|
|
import posixpath
|
|
import tempfile
|
|
import os
|
|
import subprocess
|
|
import uuid
|
|
import json
|
|
import time
|
|
from datetime import datetime
|
|
from urllib.parse import urlparse
|
|
import requests
|
|
from flask import Blueprint, request, Response, stream_with_context, jsonify, g, current_app, has_request_context
|
|
from sqlalchemy import func, desc, or_, exists, and_
|
|
from openpyxl import load_workbook
|
|
from app.services.agent_runtime_context.dify_inputs import build_chat_dify_inputs
|
|
from app.services.dify import DifyService
|
|
from app.core.config.settings import Config
|
|
from app.services.integration_api import IntegrationApiService
|
|
from app.core.decorators import require_agent_permission
|
|
from app.models import Agent, ChatLog, ChatSession, Feedback
|
|
from app import db
|
|
from app.core.errors import (
|
|
AppError,
|
|
ConflictError,
|
|
ForbiddenError,
|
|
NotFoundError,
|
|
ServiceUnavailableError,
|
|
UnauthorizedError,
|
|
ValidationError,
|
|
raise_for_status,
|
|
)
|
|
SHIPPING_NOTICE_AGENT_CODE = 'shipping_notice'
|
|
|
|
|
|
PLM_PREVIEW_SHARE_ROOT = (os.getenv('PLM_PREVIEW_SHARE_ROOT') or '\\\\192.168.0.11\\dss\\dssroot\\').strip()
|
|
|
|
|