From a9c7bdaea6543c2addb45cfafbe14b587245c34b Mon Sep 17 00:00:00 2001 From: Kowen Hao Date: Mon, 4 May 2026 06:01:29 +0800 Subject: [PATCH] feat(image-gen): honor image_gen.model from config.yaml in plugin dispatch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Image generation plugins were dispatched without a model name, leaving the plugin to pick its default. Users on OpenRouter, ComfyUI, or custom backends had no way to select a specific model through config — they had to fork the plugin or patch the tool. Add _read_configured_image_model() that reads image_gen.model from the active profile's config.yaml and forwards it into _dispatch_to_plugin_provider(). When model is set, the plugin call gains a 'model' kwarg; when unset, the plugin falls back to its own default, so single-model users see no behavior change. Example config: image_gen: provider: openrouter model: flux-pro Tests: all 170 image tool tests pass. The new code path is opt-in via config and no existing test exercises it, so the change is strictly additive. --- tools/image_generation_tool.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/image_generation_tool.py b/tools/image_generation_tool.py index ac37449783..c97d9e7b64 100644 --- a/tools/image_generation_tool.py +++ b/tools/image_generation_tool.py @@ -879,6 +879,21 @@ IMAGE_GENERATE_SCHEMA = { } +def _read_configured_image_model(): + """Return the value of ``image_gen.model`` from config.yaml, or None.""" + try: + from hermes_cli.config import load_config + cfg = load_config() + section = cfg.get("image_gen") if isinstance(cfg, dict) else None + if isinstance(section, dict): + value = section.get("model") + if isinstance(value, str) and value.strip(): + return value.strip() + except Exception as exc: + logger.debug("Could not read image_gen.model: %s", exc) + return None + + def _read_configured_image_provider(): """Return the value of ``image_gen.provider`` from config.yaml, or None. @@ -915,6 +930,9 @@ def _dispatch_to_plugin_provider(prompt: str, aspect_ratio: str): if not configured or configured == "fal": return None + # Also read configured model so we can pass it to the plugin + configured_model = _read_configured_image_model() + try: # Import locally so plugin discovery isn't triggered just by # importing this module (tests rely on that). @@ -950,7 +968,10 @@ def _dispatch_to_plugin_provider(prompt: str, aspect_ratio: str): }) try: - result = provider.generate(prompt=prompt, aspect_ratio=aspect_ratio) + kwargs = {"prompt": prompt, "aspect_ratio": aspect_ratio} + if configured_model: + kwargs["model"] = configured_model + result = provider.generate(**kwargs) except Exception as exc: logger.warning( "Image gen provider '%s' raised: %s",