Feat/ollama provider#3213
Open
Aneesh-382005 wants to merge 2 commits into
Open
Conversation
Co-authored-by: Copilot <copilot@github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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