| | |
| | | from typing import Any, Dict, Optional |
| | | |
| | | import yaml |
| | | from dotenv import load_dotenv |
| | | |
| | | logger = logging.getLogger(__name__) |
| | | |
| | | BASE_DIR = Path(__file__).resolve().parent |
| | | load_dotenv(BASE_DIR / ".env") |
| | | |
| | | CONFIG_PATH = BASE_DIR / "config.yaml" |
| | | CONFIG_EXAMPLE_PATH = BASE_DIR / "config.yaml.example" |
| | | |
| | |
| | | "base_url": "https://ark.cn-beijing.volces.com/api/v3", |
| | | "enable_proxy": False, |
| | | }, |
| | | "doubao": { |
| | | "api_key": "", |
| | | "base_url": "https://ark.cn-beijing.volces.com/api/coding/v3", |
| | | "enable_proxy": False, |
| | | }, |
| | | "kling": { |
| | | "base_url": "https://api-beijing.klingai.com", |
| | | "access_key": "", |
| | |
| | | }, |
| | | }, |
| | | "models": { |
| | | "llm": "qwen3.5-plus", |
| | | "vlm": "qwen3.5-plus", |
| | | "image_it2i": "doubao-seedream-5-0-260128", |
| | | "image_t2i": "doubao-seedream-5-0-260128", |
| | | "video": "wan2.7-i2v", |
| | | "eval": "qwen3.5-plus", |
| | | "llm": "ark-code-latest", |
| | | "vlm": "ark-code-latest", |
| | | "image_it2i": "ep-20260510144546-hwrtr", |
| | | "image_t2i": "ep-20260510144546-hwrtr", |
| | | "video": "doubao-seedance-2-0-mini-260615", |
| | | "video_first_frame": "doubao-seedance-2-0-mini-260615", |
| | | "video_start_end": "wan2.7-i2v", |
| | | "video_reference": "wan2.7-r2v", |
| | | }, |
| | | "generation": { |
| | | "style": "realistic", |
| | | "video_ratio": "16:9", |
| | | "video_resolution": "720P", |
| | | "video_generation_mode": "first_frame", |
| | | }, |
| | | } |
| | | |
| | |
| | | |
| | | def _coerce_config(data: Dict[str, Any]) -> Dict[str, Any]: |
| | | clean = _deep_merge(DEFAULT_CONFIG, data) |
| | | |
| | | # 允许使用环境变量(如 .env)来覆盖 API 秘钥配置 |
| | | if "api_providers" in clean: |
| | | for provider, values in clean["api_providers"].items(): |
| | | if provider == "common" or not isinstance(values, dict): |
| | | continue |
| | | for key in values.keys(): |
| | | env_key = f"{provider.upper()}_{key.upper()}" |
| | | if os.getenv(env_key): |
| | | values[key] = os.getenv(env_key) |
| | | clean.pop("llm", None) |
| | | raw_server = data.get("server", {}) if isinstance(data, dict) else {} |
| | | |
| | | legacy_models = data.get("models", {}) if isinstance(data, dict) else {} |
| | | if isinstance(legacy_models, dict): |
| | | for legacy_key in ("style", "video_ratio", "video_resolution"): |
| | | # Legacy config compatibility: older config.yaml stored generation settings under models.*. |
| | | if legacy_key in legacy_models and not _get(data, f"generation.{legacy_key}"): |
| | | clean.setdefault("generation", {})[legacy_key] = legacy_models[legacy_key] |
| | | clean["models"].pop(legacy_key, None) |
| | | if legacy_models.get("video") and not any( |
| | | legacy_models.get(key) for key in ("video_first_frame", "video_start_end", "video_reference") |
| | | ): |
| | | # Legacy config compatibility: older configs had one models.video instead of mode-specific video models. |
| | | clean["models"]["video_first_frame"] = legacy_models["video"] |
| | | # Legacy config compatibility: models.eval was never used by runtime agents; keep it out after load. |
| | | clean["models"].pop("eval", None) |
| | | |
| | | server = clean["server"] |
| | | server["host"] = str(server.get("host") or DEFAULT_CONFIG["server"]["host"]) |
| | |
| | | ARK_API_KEY = _get(CONFIG, "api_providers.ark.api_key") |
| | | ARK_BASE_URL = _get(CONFIG, "api_providers.ark.base_url") |
| | | ARK_ENABLE_PROXY = _get(CONFIG, "api_providers.ark.enable_proxy") |
| | | DOUBAO_API_KEY = _get(CONFIG, "api_providers.doubao.api_key") |
| | | DOUBAO_BASE_URL = _get(CONFIG, "api_providers.doubao.base_url") |
| | | DOUBAO_ENABLE_PROXY = _get(CONFIG, "api_providers.doubao.enable_proxy") |
| | | KLING_ACCESS_KEY = _get(CONFIG, "api_providers.kling.access_key") |
| | | KLING_SECRET_KEY = _get(CONFIG, "api_providers.kling.secret_key") |
| | | KLING_BASE_URL = _get(CONFIG, "api_providers.kling.base_url") |
| | |
| | | IMAGE_IT2I_MODEL = _get(CONFIG, "models.image_it2i") |
| | | IMAGE_T2I_MODEL = _get(CONFIG, "models.image_t2i") |
| | | VIDEO_MODEL = _get(CONFIG, "models.video") |
| | | VIDEO_FIRST_FRAME_MODEL = _get(CONFIG, "models.video_first_frame") |
| | | VIDEO_START_END_MODEL = _get(CONFIG, "models.video_start_end") |
| | | VIDEO_REFERENCE_MODEL = _get(CONFIG, "models.video_reference") |
| | | VIDEO_RATIO = _get(CONFIG, "generation.video_ratio") |
| | | VIDEO_RESOLUTION = _get(CONFIG, "generation.video_resolution") |
| | | VIDEO_GENERATION_MODE = _get(CONFIG, "generation.video_generation_mode") |
| | | STYLE = _get(CONFIG, "generation.style") |
| | | EVAL_MODEL = _get(CONFIG, "models.eval") |
| | | |
| | | BASE_DIR = str(BASE_DIR) |
| | | CODE_DIR = os.path.join(BASE_DIR, "code") |
| | |
| | | cls.ARK_API_KEY = _get(clean, "api_providers.ark.api_key") |
| | | cls.ARK_BASE_URL = _get(clean, "api_providers.ark.base_url") |
| | | cls.ARK_ENABLE_PROXY = _get(clean, "api_providers.ark.enable_proxy") |
| | | cls.DOUBAO_API_KEY = _get(clean, "api_providers.doubao.api_key") |
| | | cls.DOUBAO_BASE_URL = _get(clean, "api_providers.doubao.base_url") |
| | | cls.DOUBAO_ENABLE_PROXY = _get(clean, "api_providers.doubao.enable_proxy") |
| | | cls.KLING_ACCESS_KEY = _get(clean, "api_providers.kling.access_key") |
| | | cls.KLING_SECRET_KEY = _get(clean, "api_providers.kling.secret_key") |
| | | cls.KLING_BASE_URL = _get(clean, "api_providers.kling.base_url") |
| | |
| | | cls.IMAGE_IT2I_MODEL = _get(clean, "models.image_it2i") |
| | | cls.IMAGE_T2I_MODEL = _get(clean, "models.image_t2i") |
| | | cls.VIDEO_MODEL = _get(clean, "models.video") |
| | | cls.VIDEO_FIRST_FRAME_MODEL = _get(clean, "models.video_first_frame") |
| | | cls.VIDEO_START_END_MODEL = _get(clean, "models.video_start_end") |
| | | cls.VIDEO_REFERENCE_MODEL = _get(clean, "models.video_reference") |
| | | cls.VIDEO_RATIO = _get(clean, "generation.video_ratio") |
| | | cls.VIDEO_RESOLUTION = _get(clean, "generation.video_resolution") |
| | | cls.VIDEO_GENERATION_MODE = _get(clean, "generation.video_generation_mode") |
| | | cls.STYLE = _get(clean, "generation.style") |
| | | cls.EVAL_MODEL = _get(clean, "models.eval") |
| | | return cls.as_dict() |
| | | |
| | | @classmethod |