fix(config): honor explicit custom model for non-DeepSeek providers (#1714)
Summary / 概述
EN: Fixes #1714. An explicit custom model for a non‑DeepSeek provider (e.g. deepseek --provider openai --model MiniMax-M2.7) was silently replaced by a DeepSeek/provider default, so the configured model never reached the endpoint. This PR makes an explicitly‑chosen custom model pass through verbatim for every non‑DeepSeek provider.
中文: 修复 #1714。当使用非 DeepSeek 提供方并显式指定自定义模型时(例如 deepseek --provider openai --model MiniMax-M2.7),配置的模型名会被静默替换为 DeepSeek/提供方默认值,导致请求实际发送的并不是用户指定的模型。本 PR 让任何非 DeepSeek 提供方下显式指定的自定义模型原样透传。
Root cause / 根因
EN: The CLI --model handoff only ever exports DEEPSEEK_MODEL (never the provider‑specific *_MODEL var). In apply_env_overrides, DEEPSEEK_MODEL was funneled into the root default_text_model slot — a DeepSeek‑only slot the validator rejects for non‑DeepSeek IDs. Config::default_model() then treated it as a weak, normalizable default and, for an unrecognized custom model on a non‑DeepSeek provider, fell through to a DeepSeek/provider default instead of returning the user's string. This matches the maintainer's own suspicion in the v0.8.40 audit (#1736): “explicit DEEPSEEK_MODEL or --model getting overridden later by settings.provider_models or provider‑switch state.”
中文: CLI 的 --model 透传只会导出 DEEPSEEK_MODEL(永远不会导出提供方专用的 *_MODEL 变量)。apply_env_overrides 把 DEEPSEEK_MODEL 写进了根级 default_text_model 槽位——而该槽位是 DeepSeek 专用的,校验器会拒绝非 DeepSeek 的模型 ID。随后 Config::default_model() 把它当作一个可被规范化的弱默认值;对于非 DeepSeek 提供方上无法识别的自定义模型,便回退成 DeepSeek/提供方默认值,而不是返回用户指定的字符串。这与维护者在 v0.8.40 审计(#1736)中的判断一致:“显式的 DEEPSEEK_MODEL 或 --model 之后被 settings.provider_models 或切换提供方的状态覆盖。”
Fix / 修复
Two surgical changes in crates/tui/src/config.rs, reusing the existing provider‑scoped passthrough mechanism (no new code path):
apply_env_overrides: for a non‑DeepSeek provider, routeDEEPSEEK_MODELinto the active provider's model slot (mirroring the existingOPENAI_MODELbranch) instead of the DeepSeek‑only root slot. DeepSeek/DeepSeekCN behavior is unchanged.default_model(): an explicit provider‑scoped model that is not a recognized DeepSeek alias is returned verbatim for non‑DeepSeek providers, instead of falling back to a default.
中文: 在 crates/tui/src/config.rs 中做两处精准改动,复用既有的按提供方透传机制(不新增代码路径):① apply_env_overrides 对非 DeepSeek 提供方,将 DEEPSEEK_MODEL 写入当前提供方的模型槽位(与既有 OPENAI_MODEL 分支一致),而非 DeepSeek 专用根槽位;② default_model() 对非 DeepSeek 提供方,若显式模型不是已知 DeepSeek 别名,则原样返回,不再回退默认值。DeepSeek/DeepSeekCN 行为保持不变。
Scope / 改动边界
- Does not touch
normalize_model_config,provider_passes_model_through, the validator, the existingSGLANG/VLLM/OLLAMA/NVIDIA_NIM_MODELenv branches, or any other file. - Does not change DeepSeek/DeepSeekCN model resolution.
- 不改动上述函数与其他文件;不改变 DeepSeek 系列的模型解析。
Testing / 测试
New regression test deepseek_model_env_passes_custom_model_through_for_non_deepseek_providers (next to openai_provider_accepts_custom_model_and_base_url), covering: (a) provider=openai + DEEPSEEK_MODEL=MiniMax-M2.7, no OPENAI_MODEL, default base_url → default_model() == "MiniMax-M2.7"; (b) a non‑passthrough provider (novita) with the same custom model preserved verbatim.
cargo test -p deepseek-tui --bin deepseek-tui -- \
deepseek_model_env_passes_custom_model_through_for_non_deepseek_providers \
openai_provider_accepts_custom_model_and_base_url
# both pass; full config:: module: 146 passed, 0 failed
新增回归测试 deepseek_model_env_passes_custom_model_through_for_non_deepseek_providers,覆盖 OpenAI 兼容端点与一个非透传提供方两种情形;既有 openai_provider_accepts_custom_model_and_base_url 等仍全部通过。
Refs #1714, #1739, #1736.
Done in the latest push — the two logically-unreachable arms are collapsed to ApiProvider::Deepseek | ApiProvider::DeepseekCN => unreachable!("DeepSeek providers are handled in the if branch above (issue #1714)"), making it explicit that this else block is non-DeepSeek-only. No behavior change; existing regression test + clippy still green.
Thanks for the custom-model/provider fix. This was harvested into v0.8.40 release PR #1823 as commits b156d7da3 and 3adc05d62, and #1823 is now CI-green. Closing as superseded by the release branch; thank you for improving third-party OpenAI-compatible provider support.