Files
xiaoxia-saas/packages/shared/config.py
T
CI Bot 545293fe5c
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been skipped
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m39s
AI Code Review / AI Code Review (pull_request) Successful in 4m36s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 35s
feat(#674): 豆包大模型 Phase 3 - AI推荐片段编排 + 客户端抽共享层
- 豆包客户端抽 packages/shared/ai_client.py,API和Worker共用
- 配置移到 SharedSettings,两边统一读取
- Worker AI推荐接入豆包大模型,替换原stub
- 智能编排:intro/showcase/outro 三段式结构 + 转场分配
- 降级机制:无Key/调用失败/解析失败均回退本地规则
- 响应解析:格式校验+字段兜底+非法asset过滤+order排序重编号
- 新增22个worker AI单测 + 调整41个API单测mock
- 累计63个AI单测全部通过
2026-07-23 14:05:15 +08:00

75 lines
2.3 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Shared settings for API and Worker services."""
import os
from typing import Optional
from pydantic_settings import BaseSettings, SettingsConfigDict
class SharedSettings(BaseSettings):
"""Settings shared between API and Worker services."""
# Database
database_url: str = "postgresql+psycopg://postgres:postgres@localhost:5432/xiaoxia_saas"
database_pool_size: int = 20
database_max_overflow: int = 40
database_pool_timeout: int = 30
database_pool_recycle: int = 3600
# Redis
redis_url: str = "redis://localhost:6379/0"
# Celery
celery_broker_url: str = "redis://localhost:6379/0"
celery_result_backend: str = "redis://localhost:6379/1"
# OSS Aliyun
oss_endpoint: str = "oss-cn-hangzhou.aliyuncs.com"
oss_access_key_id: str = ""
oss_access_key_secret: str = ""
oss_bucket_name: str = "xiaoxia-autocut"
# CosyVoice (阿里云百炼语音合成)
cosyvoice_api_key: str = ""
cosyvoice_base_url: str = "https://dashscope.aliyuncs.com/api/v1"
cosyvoice_model: str = "cosyvoice-v3-flash"
cosyvoice_voice: str = "longxiaochun_v3" # 默认音色(v3 系列系统音色带 _v3 后缀)
cosyvoice_sample_rate: int = 22050
cosyvoice_format: str = "mp3" # 输出格式:mp3/wav/pcm
# 音色克隆模型名(固定为 voice-enrollment
cosyvoice_clone_model: str = "voice-enrollment"
# 豆包大模型(火山引擎方舟)
doubao_api_key: str = ""
doubao_model: str = "doubao-seed-1-6-250615"
doubao_base_url: str = "https://ark.cn-beijing.volces.com/api/v3"
doubao_timeout: int = 30
doubao_max_retries: int = 2
# Environment
environment: str = "development"
auto_create_schema: bool = False
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
case_sensitive=False,
extra="ignore",
)
_settings: Optional[SharedSettings] = None
def get_shared_settings() -> SharedSettings:
"""Get shared settings instance (global singleton)."""
global _settings
if _settings is None:
env = os.getenv("APP_ENV", "development")
env_file = f".env.{env}" if env != "development" else ".env"
if os.path.exists(env_file):
_settings = SharedSettings(_env_file=env_file)
else:
_settings = SharedSettings()
return _settings