Add Xiaomi MiMo provider support#87
Conversation
krazyjakee
left a comment
There was a problem hiding this comment.
Review: Add Xiaomi MiMo provider support
Verdict: solid, mergeable. One refactor worth doing first, plus a few minor notes. Branch builds clean; all tests pass locally (314 in mogen-llm, 332 in mogen-studio).
The integration is thorough and correct. Every dispatch site is covered consistently — Provider enum, LlmClient, error mapping, from_env, settings store, Studio ProviderSlot, pricing seed, CLI ProviderArg, MCP docs. No missing match arms, no unwrap/panic hazards in the new paths. xiaomi.rs faithfully follows the existing zai_chat/openai template.
Safety — good
- API-key handling matches the other providers:
from_envtrims and rejects blank, Bearer auth viaXIAOMI_API_KEY, errors map cleanly into the unifiedProviderError. - Budget enforcement, bounded timeouts, and error-body parsing are all present.
- The
MOGEN_DEBUG_HTTPpath prints only the response body (truncated, env-gated) — it does not log the request or the bearer token. No key leakage.
Alignment — excellent
- Reuses established patterns: the f32-temperature shortest-decimal workaround, the deliberate seed-omission (Xiaomi's schema has no
seed), OpenAI-compatibleimage_urlcontent parts. - Vision content ordering (image-first, text-last) intentionally matches
openai.rsrather thanzai_chat.rs(text-first) — both are documented per-provider choices, so this is fine. - Thinking mapping (Low/Medium →
disabled, High/XHigh →enabledwith larger token cap + longer timeout) is a sensible fit for Xiaomi's binary CoT toggle.
Issues to address
1. (Main) Vision-model-swap logic is now duplicated in three places. The same Zai → ZAI_VISION, Xiaomi → XIAOMI_VISION mapping appears in:
app/util/llm.rs::apply_provider_vision_model_overrideapp/wizard/pipeline.rs::apply_vision_model_if_neededcommands/generate.rs(inline)
A fourth provider with a text/vision split means updating three call sites, and missing one silently routes an image to a text model (400 or worse). Recommend centralizing as Provider::vision_model_override(self) -> Option<&'static str> in provider.rs and having all three call it. (Moving the Z.ai swap before the planner pass is a genuine improvement, though — the planner now sees the image too.)
2. (Minor) Large bundled cargo fmt churn. Much of the 490 deletions is unrelated reformatting across provider.rs, error_class.rs, workers.rs, mcp.rs, etc. It inflates the diff and mixes concerns. Ideally formatting-only changes land in a separate commit/PR.
3. (Minor) The documented verification is misleading. cargo test -p mogen-llm xiaomi reports "7 filtered out" — the xiaomi.rs module unit tests are named generically (request_body_includes_system_message, …) so the xiaomi name-filter skips them; only the mock-server integration test matches. They do pass under --lib, but the listed command gives false confidence.
4. (Nit) Pricing precision unverifiable. 0.435 / 0.87 / 0.0036 is stamped as "overseas pay-as-you-go" with no source link. Harmless given the zero-cost fallback, but a doc URL would help future maintainers.
Worth calling out as correct
The Gemini pricing matchers were tightened to require a gemini prefix so mimo-v2.5-pro can't shadow into the Gemini 2.5-pro tier. Verified every real Gemini model ID in the tree starts with gemini-, so this behavioral change to existing pricing is safe and was the right call.
Summary
Adds first-class Xiaomi MiMo support across the CLI, library, and Studio using Xiaomi's OpenAI-compatible
/v1/chat/completionsendpoint.What changed
Provider::Xiaomi/--provider xiaomiwith aliases likemimo,xiaomimimo, andxiaomi-mimomogen-llm::xiaomiclient with Xiaomi defaults (mimo-v2.5-pro,mimo-v2-flash,mimo-v2.5), Bearer auth viaXIAOMI_API_KEY, Xiaomi-specific thinking mapping, and longer timeout headroom for reasoning-enabled requestscargo run -p mogen -- ...stays usable with the larger command graphVerification
cargo checkcargo test -p mogen-llm xiaomicargo test -p mogen-studio classify_timeout_uses_specific_headline_and_hintcargo test -p mogen-studio xiaomi_image_calls_use_vision_model_before_planningcargo test -p mogen-studio text_only_calls_keep_configured_modelcargo test -p mogen-studio wizard_image_calls_use_provider_vision_modelcargo test -p mogen-studio wizard_text_calls_keep_configured_modelcargo test -p mogen-studio xiaomi_pricing_matches_overseas_ratescargo run -p mogen -- generate "a single small blue cube" --provider xiaomi --model mimo-v2-flash --thinking medium --dry-run --max-repair-iters 1Post-Deploy Monitoring & Validation
No additional operational monitoring required — this is a local CLI/desktop provider integration with no server-side deployment surface.