Initial commit: AI Video Assistant fullstack platform.
Add pipecat-based backend with WebRTC/WS voice routes, Next.js frontend, and Docker Compose orchestration. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
66
backend/schemas.py
Normal file
66
backend/schemas.py
Normal file
@@ -0,0 +1,66 @@
|
||||
"""面向前端的请求/响应 DTO。与 DB 模型解耦,**响应里的 key 一律打码**。
|
||||
|
||||
凭证 DTO 字段对齐前端 ComponentsModelsPage 的 ModelResource:
|
||||
JSON 用 camelCase(modelId/interfaceType/apiUrl/apiKey),Python 内部用 snake_case,
|
||||
靠 Pydantic alias 自动互转。FastAPI 响应默认 by_alias=True,所以出参也是 camelCase。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from pydantic.alias_generators import to_camel
|
||||
|
||||
RuntimeMode = Literal["pipeline", "realtime"]
|
||||
ModelType = Literal["LLM", "ASR", "TTS", "Realtime", "Embedding"]
|
||||
InterfaceType = Literal["openai", "xfyun", "dashscope", "gemini"]
|
||||
|
||||
|
||||
class CamelModel(BaseModel):
|
||||
"""JSON camelCase ↔ Python snake_case。protected_namespaces 关掉以允许 model_id。"""
|
||||
|
||||
model_config = ConfigDict(
|
||||
alias_generator=to_camel,
|
||||
populate_by_name=True,
|
||||
protected_namespaces=(),
|
||||
)
|
||||
|
||||
|
||||
# ---------- 助手 ----------
|
||||
class AssistantUpsert(CamelModel):
|
||||
name: str
|
||||
greeting: str = ""
|
||||
prompt: str = ""
|
||||
runtime_mode: RuntimeMode = "pipeline"
|
||||
model: str = ""
|
||||
asr: str = ""
|
||||
voice: str = ""
|
||||
enable_interrupt: bool = True
|
||||
|
||||
|
||||
class AssistantOut(AssistantUpsert):
|
||||
id: str
|
||||
updated_at: str | None = None
|
||||
|
||||
|
||||
# ---------- 模型凭证(对齐前端 ModelResource) ----------
|
||||
class CredentialUpsert(CamelModel):
|
||||
name: str = "" # 资源名称
|
||||
model_id: str = "" # 模型ID
|
||||
type: ModelType # LLM/ASR/TTS/Realtime/Embedding
|
||||
interface_type: InterfaceType = "openai" # openai/xfyun/dashscope/gemini
|
||||
api_url: str = ""
|
||||
api_key: str = "" # 写时:占位符/空表示不改
|
||||
is_default: bool = False
|
||||
|
||||
|
||||
class CredentialOut(CamelModel):
|
||||
id: str
|
||||
name: str
|
||||
model_id: str
|
||||
type: str
|
||||
interface_type: str
|
||||
api_url: str
|
||||
api_key: str # 读时:打码后的值
|
||||
is_default: bool
|
||||
Reference in New Issue
Block a user