Skip to content

fix: forward base URL overrides to active providers#1313

Open
reidliu41 wants to merge 1 commit intoHmbown:mainfrom
reidliu41:fix/provider-base-url-forwarding
Open

fix: forward base URL overrides to active providers#1313
reidliu41 wants to merge 1 commit intoHmbown:mainfrom
reidliu41:fix/provider-base-url-forwarding

Conversation

@reidliu41
Copy link
Copy Markdown
Contributor

Summary

Fixes provider base URL overrides for self-hosted providers.

deepseek --provider ollama --base-url ... and deepseek --provider vllm --base-url ...
were still resolving to the default localhost endpoints. The dispatcher forwards
--base-url as DEEPSEEK_BASE_URL, but the TUI config loader only routed that
value into a few provider-specific config blocks. For Ollama and vLLM it landed
on the legacy root base_url, which those providers do not read.

This change routes DEEPSEEK_BASE_URL into the active provider's config block,
so Ollama and vLLM honor --base-url correctly. Existing provider-specific env
vars such as OLLAMA_BASE_URL and VLLM_BASE_URL continue to work.

$   OLLAMA_BASE_URL=http://10.0.0.3:11434/v1 .deepseek --provider ollama doctor --json | jq -r '.base_url'
http://10.0.0.3:11434/v1

I$   VLLM_BASE_URL=http://10.0.0.3:8000/v1 .deepseek --provider vllm doctor --json | jq -r '.base_url'
http://10.0.0.3:8000/v1

fixes: #1308

Testing

  • cargo test --all-features
  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features

Checklist

  • Updated docs or comments as needed
  • Added or updated tests where relevant
  • Verified TUI behavior manually if UI changes

  Route DEEPSEEK_BASE_URL through the active provider config instead of leaving
  self-hosted providers on their localhost defaults. This makes --base-url work
  for Ollama and vLLM while preserving provider-specific env overrides.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the apply_env_overrides function in crates/tui/src/config.rs to explicitly handle the DEEPSEEK_BASE_URL environment variable for several API providers, replacing a previous catch-all implementation. It also introduces a new test case to verify that these overrides correctly apply to self-hosted providers like Ollama and Vllm. Feedback suggests refactoring the repetitive logic used to update provider-specific base URLs to reduce code duplication and improve maintainability.

Comment thread crates/tui/src/config.rs
Comment on lines +1913 to 1954
ApiProvider::Openrouter => {
config
.providers
.get_or_insert_with(ProvidersConfig::default)
.openrouter
.base_url = Some(value);
}
ApiProvider::Novita => {
config
.providers
.get_or_insert_with(ProvidersConfig::default)
.novita
.base_url = Some(value);
}
ApiProvider::Fireworks => {
config
.providers
.get_or_insert_with(ProvidersConfig::default)
.fireworks
.base_url = Some(value);
}
ApiProvider::Sglang => {
config
.providers
.get_or_insert_with(ProvidersConfig::default)
.sglang
.base_url = Some(value);
}
ApiProvider::Vllm => {
config
.providers
.get_or_insert_with(ProvidersConfig::default)
.vllm
.base_url = Some(value);
}
ApiProvider::Ollama => {
config
.providers
.get_or_insert_with(ProvidersConfig::default)
.ollama
.base_url = Some(value);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There's a lot of repeated code here for handling different providers. You can refactor this to reduce duplication by using a match binding and another match to get the mutable provider config. This will make the code more maintainable if more providers are added in the future.

            provider @ (ApiProvider::Openrouter
            | ApiProvider::Novita
            | ApiProvider::Fireworks
            | ApiProvider::Sglang
            | ApiProvider::Vllm
            | ApiProvider::Ollama) => {
                let providers = config.providers.get_or_insert_with(ProvidersConfig::default);
                let provider_config = match provider {
                    ApiProvider::Openrouter => &mut providers.openrouter,
                    ApiProvider::Novita => &mut providers.novita,
                    ApiProvider::Fireworks => &mut providers.fireworks,
                    ApiProvider::Sglang => &mut providers.sglang,
                    ApiProvider::Vllm => &mut providers.vllm,
                    ApiProvider::Ollama => &mut providers.ollama,
                    _ => unreachable!(),
                };
                provider_config.base_url = Some(value);
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

set base_url for ollama & vllm

1 participant