feat: add visual settings and readiness gate
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
from dataclasses import dataclass
|
||||
from collections.abc import Mapping
|
||||
from typing import Any
|
||||
|
||||
from app.config import Settings
|
||||
|
||||
@@ -15,35 +17,27 @@ class ProviderCapability:
|
||||
|
||||
|
||||
class ModelRouter:
|
||||
def __init__(self, settings: Settings) -> None:
|
||||
def __init__(self, settings: Settings | Mapping[str, Any]) -> None:
|
||||
self.settings = settings
|
||||
|
||||
def _value(self, key: str, default: str = "") -> str:
|
||||
if isinstance(self.settings, Mapping):
|
||||
return str(self.settings.get(key, default) or "")
|
||||
return str(getattr(self.settings, key, default) or "")
|
||||
|
||||
def capabilities(self) -> list[ProviderCapability]:
|
||||
return [
|
||||
ProviderCapability(
|
||||
provider="seedream",
|
||||
configured=_configured(self.settings.ark_api_key)
|
||||
and bool(self.settings.seedream_model_endpoint),
|
||||
strengths=("中文风格指令", "快速方向探索"),
|
||||
),
|
||||
ProviderCapability(
|
||||
provider="openai",
|
||||
configured=_configured(self.settings.openai_api_key),
|
||||
strengths=("局部编辑", "多轮一致性", "遮罩修改"),
|
||||
),
|
||||
ProviderCapability(
|
||||
provider="gemini",
|
||||
configured=_configured(self.settings.gemini_api_key),
|
||||
strengths=("多参考图理解", "复杂视觉指令"),
|
||||
provider=self._value("ai_provider", "custom"),
|
||||
configured=_configured(self._value("ai_api_key"))
|
||||
and bool(self._value("ai_base_url"))
|
||||
and bool(self._value("image_model")),
|
||||
strengths=("统一模型网关", "空间理解", "图像生成与编辑"),
|
||||
),
|
||||
]
|
||||
|
||||
def choose_image_provider(self, task: str) -> str:
|
||||
configured = {item.provider for item in self.capabilities() if item.configured}
|
||||
priorities = [item.strip() for item in self.settings.image_provider_priority.split(",")]
|
||||
if task == "masked_edit" and "openai" in configured:
|
||||
return "openai"
|
||||
for provider in priorities:
|
||||
if provider in configured:
|
||||
return provider
|
||||
configured = [item.provider for item in self.capabilities() if item.configured]
|
||||
if configured:
|
||||
return configured[0]
|
||||
raise RuntimeError("No image provider is configured.")
|
||||
|
||||
Reference in New Issue
Block a user