Update backend schema

This commit is contained in:
Xin Wang
2026-02-08 14:26:19 +08:00
parent b9a315177a
commit 727fe8a997
16 changed files with 1532 additions and 94 deletions

View File

@@ -1,6 +1,6 @@
from datetime import datetime
from typing import List, Optional
from sqlalchemy import String, Integer, DateTime, Text, Float, ForeignKey, JSON
from sqlalchemy import String, Integer, DateTime, Text, Float, ForeignKey, JSON, Enum
from sqlalchemy.orm import Mapped, mapped_column, relationship
from .db import Base
@@ -15,18 +15,72 @@ class User(Base):
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
# ============ Voice ============
class Voice(Base):
__tablename__ = "voices"
id: Mapped[str] = mapped_column(String(64), primary_key=True)
user_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("users.id"), index=True, nullable=True)
name: Mapped[str] = mapped_column(String(128), nullable=False)
vendor: Mapped[str] = mapped_column(String(64), nullable=False)
gender: Mapped[str] = mapped_column(String(32), nullable=False)
language: Mapped[str] = mapped_column(String(16), nullable=False)
description: Mapped[str] = mapped_column(String(255), nullable=False)
voice_params: Mapped[dict] = mapped_column(JSON, default=dict)
model: Mapped[Optional[str]] = mapped_column(String(128), nullable=True) # 厂商语音模型标识
voice_key: Mapped[Optional[str]] = mapped_column(String(128), nullable=True) # 厂商voice_key
speed: Mapped[float] = mapped_column(Float, default=1.0)
gain: Mapped[int] = mapped_column(Integer, default=0)
pitch: Mapped[int] = mapped_column(Integer, default=0)
enabled: Mapped[bool] = mapped_column(default=True)
is_system: Mapped[bool] = mapped_column(default=False)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
user = relationship("User", foreign_keys=[user_id])
# ============ LLM Model ============
class LLMModel(Base):
__tablename__ = "llm_models"
id: Mapped[str] = mapped_column(String(64), primary_key=True)
user_id: Mapped[int] = mapped_column(Integer, ForeignKey("users.id"), index=True)
name: Mapped[str] = mapped_column(String(128), nullable=False)
vendor: Mapped[str] = mapped_column(String(64), nullable=False)
type: Mapped[str] = mapped_column(String(32), nullable=False) # text/embedding/rerank
base_url: Mapped[str] = mapped_column(String(512), nullable=False)
api_key: Mapped[str] = mapped_column(String(512), nullable=False)
model_name: Mapped[Optional[str]] = mapped_column(String(128), nullable=True)
temperature: Mapped[Optional[float]] = mapped_column(Float, nullable=True)
context_length: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
enabled: Mapped[bool] = mapped_column(default=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
user = relationship("User")
# ============ ASR Model ============
class ASRModel(Base):
__tablename__ = "asr_models"
id: Mapped[str] = mapped_column(String(64), primary_key=True)
user_id: Mapped[int] = mapped_column(Integer, ForeignKey("users.id"), index=True)
name: Mapped[str] = mapped_column(String(128), nullable=False)
vendor: Mapped[str] = mapped_column(String(64), nullable=False)
language: Mapped[str] = mapped_column(String(32), nullable=False) # zh/en/Multi-lingual
base_url: Mapped[str] = mapped_column(String(512), nullable=False)
api_key: Mapped[str] = mapped_column(String(512), nullable=False)
model_name: Mapped[Optional[str]] = mapped_column(String(128), nullable=True)
hotwords: Mapped[dict] = mapped_column(JSON, default=list)
enable_punctuation: Mapped[bool] = mapped_column(default=True)
enable_normalization: Mapped[bool] = mapped_column(default=True)
enabled: Mapped[bool] = mapped_column(default=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
user = relationship("User")
# ============ Assistant ============
class Assistant(Base):
__tablename__ = "assistants"
@@ -46,6 +100,11 @@ class Assistant(Base):
config_mode: Mapped[str] = mapped_column(String(32), default="platform")
api_url: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
api_key: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
# 模型关联
llm_model_id: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
asr_model_id: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
embedding_model_id: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
rerank_model_id: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
@@ -53,6 +112,7 @@ class Assistant(Base):
call_records = relationship("CallRecord", back_populates="assistant")
# ============ Knowledge Base ============
class KnowledgeBase(Base):
__tablename__ = "knowledge_bases"
@@ -92,6 +152,7 @@ class KnowledgeDocument(Base):
kb = relationship("KnowledgeBase", back_populates="documents")
# ============ Workflow ============
class Workflow(Base):
__tablename__ = "workflows"
@@ -108,6 +169,7 @@ class Workflow(Base):
user = relationship("User")
# ============ Call Record ============
class CallRecord(Base):
__tablename__ = "call_records"