feat(ai): 新增智能助手功能模块

feat(backend): 添加ChromaDB向量数据库支持
feat(backend): 实现智能体配置、知识库和文档管理
feat(backend): 重构WebSocket聊天服务为AgentService
feat(frontend): 实现完整的聊天界面组件
feat(frontend): 添加智能体配置、知识库和文档管理页面
fix(user): 修复用户导入时性别转换问题
style(import): 优化导入组件加载状态处理
This commit is contained in:
zhangtao
2026-02-09 01:22:48 +08:00
parent b4dcdfa1ab
commit 45dad1e256
34 changed files with 5803 additions and 1214 deletions
@@ -1,24 +1,60 @@
from sqlalchemy import JSON, Integer, String
from sqlalchemy import JSON, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from app.core.base_model import ModelMixin, UserMixin
class McpModel(ModelMixin, UserMixin):
class AgentConfigModel(ModelMixin, UserMixin):
"""
MCP 服务器
MCP类型:
- 0: stdio (标准输入输出)
- 1: sse (Server-Sent Events)
智能体配置
"""
__tablename__: str = "app_ai_mcp"
__table_args__: dict[str, str] = {"comment": "MCP 服务器"}
__tablename__: str = "app_ai_agent_config"
__table_args__: dict[str, str] = {"comment": "智能体配置"}
__loader_options__: list[str] = ["created_by", "updated_by"]
name: Mapped[str] = mapped_column(String(50), comment="MCP 名称")
type: Mapped[int] = mapped_column(Integer, default=0, comment="MCP 类型(0:stdio 1:sse)")
url: Mapped[str | None] = mapped_column(String(255), default=None, comment="远程 SSE 地址")
command: Mapped[str | None] = mapped_column(String(255), default=None, comment="MCP 命令")
args: Mapped[str | None] = mapped_column(String(255), default=None, comment="MCP 命令参数")
env: Mapped[dict[str, str] | None] = mapped_column(JSON(), default=None, comment="MCP 环境变量")
name: Mapped[str] = mapped_column(String(100), comment="智能体名称")
provider: Mapped[str] = mapped_column(String(50), default="openai", comment="LLM 供应商")
model: Mapped[str] = mapped_column(String(100), comment="LLM 名称")
api_key: Mapped[str] = mapped_column(String(500), comment="LLM API Key")
base_url: Mapped[str | None] = mapped_column(String(500), default=None, comment="自定义 LLM API 地址")
temperature: Mapped[float] = mapped_column(Integer, default=70, comment="温度参数 (0-100)")
system_prompt: Mapped[str] = mapped_column(Text, comment="系统提示词")
is_default: Mapped[bool] = mapped_column(Integer, default=0, comment="是否默认配置")
is_active: Mapped[bool] = mapped_column(Integer, default=1, comment="是否启用")
class KnowledgeModel(ModelMixin, UserMixin):
"""
知识库表
"""
__tablename__: str = "app_ai_knowledge"
__table_args__: dict[str, str] = {"comment": "知识库表"}
__loader_options__: list[str] = ["created_by", "updated_by"]
name: Mapped[str] = mapped_column(String(100), comment="知识库名称")
description: Mapped[str | None] = mapped_column(String(500), default=None, comment="知识库描述")
embedding_model: Mapped[str] = mapped_column(String(100), default="openai", comment="嵌入模型")
chunk_size: Mapped[int] = mapped_column(Integer, default=500, comment="分块大小")
chunk_overlap: Mapped[int] = mapped_column(Integer, default=50, comment="分块重叠大小")
is_active: Mapped[bool] = mapped_column(Integer, default=1, comment="是否启用")
class KnowledgeDocumentModel(ModelMixin, UserMixin):
"""
知识库文档表
"""
__tablename__: str = "app_ai_knowledge_document"
__table_args__: dict[str, str] = {"comment": "知识库文档表"}
__loader_options__: list[str] = ["created_by", "updated_by"]
knowledge_id: Mapped[int] = mapped_column(Integer, comment="知识库ID")
title: Mapped[str] = mapped_column(String(200), comment="文档标题")
content: Mapped[str] = mapped_column(Text, comment="文档内容")
file_type: Mapped[str] = mapped_column(String(50), default="text", comment="文件类型")
file_path: Mapped[str | None] = mapped_column(String(500), default=None, comment="文件路径")
meta_data: Mapped[dict[str, str] | None] = mapped_column(JSON(), default=None, comment="元数据")
chunk_count: Mapped[int] = mapped_column(Integer, default=0, comment="分块数量")
is_indexed: Mapped[bool] = mapped_column(Integer, default=0, comment="是否已索引")