The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(xai): forward image_gen.model kwarg to _resolve_model in generate()
srojk34008d469991ff
diff --git a/plugins/image_gen/xai/__init__.py b/plugins/image_gen/xai/__init__.pyindex 354e3addc75..081748ed1b9 100644--- a/plugins/image_gen/xai/__init__.py+++ b/plugins/image_gen/xai/__init__.py@@ -194,14 +194,25 @@ def _load_xai_config() -> Dict[str, Any]:return {}-def _resolve_model() -> Tuple[str, Dict[str, Any]]:+def _resolve_model(caller_model: Optional[str] = None) -> Tuple[str, Dict[str, Any]]:"""Decide which model to use and return ``(model_id, meta)``.- Overrides are validated against the merged live+static catalog, so a- newly released xAI model can be selected the day it appears in the+ Priority:+ 1. Caller-supplied ``caller_model`` — the dispatcher forwards top-level+ ``image_gen.model`` (what ``hermes tools`` writes) as the ``model``+ kwarg, mirroring the openrouter provider.+ 2. ``XAI_IMAGE_MODEL`` env override.+ 3. Scoped ``image_gen.xai.model`` in config.yaml.+ 4. :data:`DEFAULT_MODEL`.++ Every candidate is validated against the merged live+static catalog,+ so a newly released xAI model is selectable the day it appears in thelive catalog — no code change required."""catalog = _catalog()+ if caller_model and caller_model in catalog:+ return caller_model, catalog[caller_model]+env_override = os.environ.get("XAI_IMAGE_MODEL")if env_override and env_override in catalog:return env_override, catalog[env_override]@@ -357,7 +368,7 @@ class XAIImageGenProvider(ImageGenProvider):aspect_ratio=aspect_ratio,)- model_id, meta = _resolve_model()+ model_id, meta = _resolve_model(kwargs.get("model"))aspect = resolve_aspect_ratio(aspect_ratio)xai_ar = _XAI_ASPECT_RATIOS.get(aspect, "1:1")resolution = _resolve_resolution()diff --git a/tests/plugins/image_gen/test_xai_provider.py b/tests/plugins/image_gen/test_xai_provider.pyindex 99f33333f13..0db7f1c20bd 100644--- a/tests/plugins/image_gen/test_xai_provider.py+++ b/tests/plugins/image_gen/test_xai_provider.py@@ -124,6 +124,43 @@ class TestConfig:model_id, _ = _resolve_model()assert model_id == "grok-imagine-image"+ def test_caller_model_overrides_env(self, monkeypatch):+ """caller_model (from image_gen.model config key) must take priority+ over XAI_IMAGE_MODEL env — mirrors the fix applied to the openrouter+ provider in #55672."""+ monkeypatch.setenv("XAI_IMAGE_MODEL", "grok-imagine-image")+ from plugins.image_gen.xai import _resolve_model++ model_id, _ = _resolve_model("grok-imagine-image-quality")+ assert model_id == "grok-imagine-image-quality"++ def test_unknown_caller_model_falls_back_to_env(self, monkeypatch):+ """An unrecognised caller_model must not crash — fall through to env."""+ monkeypatch.setenv("XAI_IMAGE_MODEL", "grok-imagine-image")+ from plugins.image_gen.xai import _resolve_model++ model_id, _ = _resolve_model("not-a-real-model")+ assert model_id == "grok-imagine-image"++ def test_model_kwarg_forwarded_to_generate(self):+ """generate(model=...) must use the supplied model, not the default."""+ from plugins.image_gen.xai import XAIImageGenProvider++ mock_resp = MagicMock()+ mock_resp.status_code = 200+ mock_resp.raise_for_status = MagicMock()+ mock_resp.json.return_value = {"data": [{"b64_json": "dGVzdA=="}]}++ with patch("plugins.image_gen.xai.requests.post", return_value=mock_resp) as mock_post:+ with patch("plugins.image_gen.xai.save_b64_image", return_value="/tmp/out.png"):+ provider = XAIImageGenProvider()+ result = provider.generate(prompt="test", model="grok-imagine-image-quality")++ assert result["success"] is True+ assert result["model"] == "grok-imagine-image-quality"+ payload = mock_post.call_args.kwargs.get("json") or mock_post.call_args[1].get("json", {})+ assert payload.get("model") == "grok-imagine-image-quality"+# ---------------------------------------------------------------------------# Live catalog merge tests