Feat/ollama provider#3213
Conversation
Co-authored-by: Copilot <copilot@github.com>
|
Thanks for the contribution! The Ollama provider approach is solid — using However, the diff in Could you rebase this on the latest main and fix the conflict in Once the diff is clean I'm happy to merge. |
- OLLAMA_HOST takes priority over OPENAI_BASE_URL for local Ollama instances - No API key required; placeholder token used for Authorization header - Model names like 'qwen3:8b' bypass strict provider/model syntax validation - detect_provider_kind() checks OLLAMA_HOST first in routing cascade - ProviderClient dispatch uses from_ollama_env() when OLLAMA_HOST is set - Updated USAGE.md and docs with OLLAMA_HOST as preferred env var - Added OLLAMA_CONFIG constant and from_ollama_env() to openai_compat - Added test_ollama_host_bypasses_model_validation unit test - Supersedes PR #3213 (which had a duplicate if-let bug in mod.rs)
|
Superseded by commit be8112f which adds native Ollama support via env var. This PR's approach was sound but had a duplicate bug in . The merged implementation uses as the preferred single env var, bypasses model syntax validation for Ollama names, and requires no API key. |
|
Thanks for reviewing and cleaning this up. I'll follow up with generic local provider support for all sorts of frameworks. |
|
Nice work on the Ollama integration. The approach of using OLLAMA_HOST to bypass colon-based model name parsing is clean. For the follow-up on generic local provider support across LM Studio/llama.cpp/vLLM, would it make sense to also consider a config-based provider registry so users can add custom endpoints without code changes? That would make the system extensible beyond the built-in providers. |
- OLLAMA_HOST takes priority over OPENAI_BASE_URL for local Ollama instances - No API key required; placeholder token used for Authorization header - Model names like 'qwen3:8b' bypass strict provider/model syntax validation - detect_provider_kind() checks OLLAMA_HOST first in routing cascade - ProviderClient dispatch uses from_ollama_env() when OLLAMA_HOST is set - Updated USAGE.md and docs with OLLAMA_HOST as preferred env var - Added OLLAMA_CONFIG constant and from_ollama_env() to openai_compat - Added test_ollama_host_bypasses_model_validation unit test - Supersedes PR ultraworkers#3213 (which had a duplicate if-let bug in mod.rs)
That's the direction I am thinking as well. A config based registry makes more sense than handling different Local LLM frameworks as edge cases. I'm planning to work on this. |
Summary
The codebase already acknowledged this gap in a comment in
rust/crates/api/src/providers/mod.rs:The routing logic beneath it was correct. But two layers upstream were
still blocking local model names before routing ever ran.
Before this PR, the intended workaround was:
This required three env vars, a fake API key, and a
provider/prefixthat Ollama doesn't understand, and it still broke due to a logic bug in
wire_model_for_base_urlwhere an innermatches!could never fire,causing the full
openai/qwen2.5-coder:7bslug to reach Ollama's APIinstead of the bare model name.
After this PR:
One env var. No prefix. No fake key. Matches Ollama's own convention.
What was blocking it
Two separate layers rejected local model names before routing logic ran:
validate_model_syntax()inrusty-claude-cli/src/main.rsenforcedprovider/modelformat on every model name unconditionally.detect_provider_kind()inproviders/mod.rsmatched theqwenprefix and routed to DashScope regardless of what endpoint was configured.
What this PR changes
rusty-claude-cli/src/main.rs- ifOLLAMA_HOSTis set, skip theprovider/modelformat requirement. Empty strings still rejected.providers/mod.rs- ifOLLAMA_HOSTis set, skip prefix matchingand route directly to the OpenAI-compatible backend.
providers/openai_compat.rs- addsOLLAMA_CONFIGconstant andfrom_ollama_env()constructor that readsOLLAMA_HOST, appends/v1,and sets a dummy api_key since Ollama requires no auth.
client.rs- in theOpenAidispatch arm, whenOLLAMA_HOSTis set,use
from_ollama_env()instead of the standard constructor.docs/local-openai-compatible-providers.mdandUSAGE.mdupdated todocument
OLLAMA_HOSTas the preferred Ollama path.Follow-up work not in this PR
ProviderKind::Ollamaas a dedicated variant so/doctorshows"Ollama" as the provider name rather than "OpenAI"
function calling
Anti-slop triage
claw --model "qwen2.5-coder:7b" prompt "x"returnsinvalid model syntaxon unpatched main. With this patch andOLLAMA_HOST=http://127.0.0.1:11434,qwen2.5-coder:7brespondscorrectly. Regression test added in
alias_resolution_tests.Verification
git diff --checkpasses.Resolution gate