feat(translate): 接入腾讯 MaaS u2 作为 TMT 备用翻译通道

新通道:腾讯 MaaS u2 模型(云知声),OpenAI 兼容协议
- 端点:https://maas-api.hivoice.cn/v1
- 模型:u2(翻译专用,实测 + 锁定 prompt 后译文质量稳定)
- 备用链路:TMT 配额耗尽 / TMT 失败时自动降级到 MaaS

关键 prompt 工程(锁定):
- 必须用 user 提供的固定中文 prompt,否则 u2 会把译文放进 reasoning_content 而 content 返乱码
- 限定只接 EN/JA → ZH
- 中文输入固定返回拒绝文案

新增/改动:
- backend/app/services/translation/tencent_maas.py: 新建
- backend/app/services/translation/service.py: 备用链 maas → local,初始化失败友好降级
- backend/app/config.py: 加 tencent_maas_* 4 个配置
- .env.example: 文档化
This commit is contained in:
Mavis
2026-06-09 17:33:45 +08:00
parent a5bfb7d49a
commit 3e56fed541
4 changed files with 227 additions and 24 deletions

View File

@@ -82,6 +82,15 @@ class Settings(BaseSettings):
local_translate_model: str = "nllb-200-distilled-600M"
local_translate_device: str = "cpu"
# ===== 腾讯 MaaS(OpenAI 兼容翻译备用通道)=====
# 用法:腾讯云 MaaS 提供的翻译模型,通过 OpenAI 协议调用
# 留空 api_key = 不启用该 provider
tencent_maas_api_key: str = ""
tencent_maas_base_url: str = "https://maas-api.hivoice.cn/v1"
tencent_maas_model: str = "u2"
# 每篇调用间隔(秒),与 LLM 客户端解耦
tencent_maas_interval_sec: float = 1.0
# ===== 抓取 =====
fetch_global_qps: int = 4
fetch_timeout: int = 20