94 lines
3.7 KiB
Python
94 lines
3.7 KiB
Python
"""
|
||
API 响应模型 — 用于 Swagger 文档展示响应体结构
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from pydantic import BaseModel, Field
|
||
|
||
|
||
# ─── 通用 ────────────────────────────────────────────────
|
||
|
||
|
||
class ErrorDetail(BaseModel):
|
||
Code: int | str = Field(..., description="错误码", examples=[-1])
|
||
Message: str = Field(..., description="错误描述", examples=["参数缺失"])
|
||
|
||
|
||
class ResponseMetadata(BaseModel):
|
||
Action: str = Field(..., description="接口名称", examples=["getScenes"])
|
||
Error: ErrorDetail | None = Field(default=None, description="仅失败时存在")
|
||
|
||
|
||
class AuthFailResponse(BaseModel):
|
||
"""鉴权失败"""
|
||
code: int = Field(401, description="状态码")
|
||
message: str = Field("鉴权失败", description="错误信息")
|
||
|
||
|
||
# ─── getScenes ───────────────────────────────────────────
|
||
|
||
|
||
class SceneInfo(BaseModel):
|
||
id: str = Field(..., description="场景唯一标识,后续接口的 SceneID 取此值", examples=["Custom"])
|
||
name: str = Field(..., description="场景显示名称", examples=["小块"])
|
||
icon: str = Field(..., description="场景头像 URL")
|
||
botName: str | None = Field(None, description="AI Bot 在 RTC 房间中的 UserId")
|
||
isInterruptMode: bool = Field(..., description="是否开启用户打断模式")
|
||
isVision: bool | None = Field(None, description="是否开启视觉理解能力")
|
||
isScreenMode: bool = Field(False, description="是否为屏幕共享模式")
|
||
isAvatarScene: bool | None = Field(None, description="是否为数字人场景")
|
||
avatarBgUrl: str | None = Field(None, description="数字人背景图 URL")
|
||
|
||
|
||
class RTCInfo(BaseModel):
|
||
AppId: str = Field(..., description="火山引擎 RTC AppId")
|
||
RoomId: str = Field(..., description="本次生成的房间 ID(UUID)")
|
||
UserId: str = Field(..., description="本次生成的用户 ID(UUID)")
|
||
Token: str = Field(..., description="RTC 入房 Token,24 小时有效")
|
||
TaskId: str = Field(..., description="语音任务 ID,StopVoiceChat 时需要")
|
||
|
||
|
||
class SceneItem(BaseModel):
|
||
scene: SceneInfo
|
||
rtc: RTCInfo
|
||
|
||
|
||
class GetScenesResult(BaseModel):
|
||
scenes: list[SceneItem] = Field(..., description="场景列表")
|
||
|
||
|
||
class GetScenesResponse(BaseModel):
|
||
"""获取场景列表成功响应"""
|
||
ResponseMetadata: ResponseMetadata
|
||
Result: GetScenesResult
|
||
|
||
|
||
# ─── proxy ───────────────────────────────────────────────
|
||
|
||
|
||
class ProxyResultData(BaseModel):
|
||
Message: str = Field(..., description="结果信息", examples=["success"])
|
||
|
||
|
||
class ProxyResponseMetadata(BaseModel):
|
||
RequestId: str | None = Field(None, description="火山引擎请求 ID")
|
||
Action: str = Field(..., description="操作类型", examples=["StartVoiceChat"])
|
||
Version: str = Field(..., description="OpenAPI 版本", examples=["2025-06-01"])
|
||
Service: str = Field("rtc", description="服务名")
|
||
Error: ErrorDetail | None = Field(default=None, description="仅失败时存在")
|
||
|
||
|
||
class ProxyResponse(BaseModel):
|
||
"""代理接口成功响应(透传火山引擎返回)"""
|
||
ResponseMetadata: ProxyResponseMetadata
|
||
Result: ProxyResultData | None = Field(None, description="成功时的结果数据")
|
||
|
||
|
||
# ─── session/history ─────────────────────────────────────
|
||
|
||
|
||
class SessionHistoryResponse(BaseModel):
|
||
"""写入历史上下文成功响应"""
|
||
code: int = Field(200, description="状态码", examples=[200])
|