refactor(image-generation): introduce provider registry to eliminate manual wiring
Adds ImageGenerationProvider ABC with shared __init__, _http_post(), and _require_images(). Introduces _IMAGE_GEN_PROVIDERS registry with register/get/image_gen_provider_configs() helpers. Four existing providers (OpenRouter, AIHubMix, Gemini, MiniMax) now inherit from the base class and self-register. Adding a new provider only requires writing one class + one registration line. Eliminates if/else chains in the tool dispatch and hardcoded provider config dicts in commands.py (3 sites) and nanobot.py (1 site). Fixes the agent CLI command missing image_generation_provider_configs entirely. Also simplifies test monkeypatch targets to patch the registry lookup.
This commit is contained in:
+2
-6
@@ -8,6 +8,7 @@ from typing import Any
|
||||
|
||||
from nanobot.agent.hook import AgentHook, SDKCaptureHook
|
||||
from nanobot.agent.loop import AgentLoop
|
||||
from nanobot.providers.image_generation import image_gen_provider_configs
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
@@ -63,12 +64,7 @@ class Nanobot:
|
||||
|
||||
loop = AgentLoop.from_config(
|
||||
config,
|
||||
image_generation_provider_configs={
|
||||
"openrouter": config.providers.openrouter,
|
||||
"aihubmix": config.providers.aihubmix,
|
||||
"minimax": config.providers.minimax,
|
||||
"gemini": config.providers.gemini,
|
||||
},
|
||||
image_generation_provider_configs=image_gen_provider_configs(config),
|
||||
)
|
||||
return cls(loop)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user