feat(translate): 加星火 Spark(Lite)作为优先翻译引擎

- 新增 app/services/translation/spark.py: OpenAI 兼容协议客户端,
  URL = https://spark-api-open.xf-yun.com/v1/chat/completions,
  鉴权 = Bearer <APIPassword>, model = lite(默认)/generalv3.5/4.0Ultra 可切换
- service.py 引擎链路调整为: spark → tencent(配额)→ maas → agnes → local。
  优先级降序: spark 配了 key 就用它,失败再走 tencent(继续吃配额,不绕过)。
  要完全绕开 tencent,把 TENCENTCLOUD_SECRET_ID 留空即可。
- 配置: 新增 SPARK_API_PASSWORD / SPARK_BASE_URL / SPARK_MODEL / SPARK_INTERVAL_SEC
  (留空 SPARK_API_PASSWORD = 走原 tencent 主链路,向后兼容)
- 缓存白名单 / 配额计数逻辑保持原行为,只把 spark 加入允许缓存的引擎集合
This commit is contained in:
Mavis
2026-06-10 23:14:20 +08:00
parent 759eefabc3
commit b27643123e
4 changed files with 172 additions and 20 deletions

View File

@@ -70,6 +70,13 @@ class Settings(BaseSettings):
tencent_tmt_quota_buffer: float = 0.05
tencent_tmt_max_chars_per_req: int = 4500
# ===== 星火 Spark(优先翻译;Lite/免费)=====
# 留空 = 不启用星火(直接走腾讯 TMT)
spark_api_password: str = ""
spark_base_url: str = "https://spark-api-open.xf-yun.com/v1"
spark_model: str = "lite"
spark_interval_sec: float = 1.0
@field_validator("tencent_tmt_quota_buffer")
@classmethod
def _check_buffer(cls, v: float) -> float: