feat(ollama): add OpenAI- and Anthropic-compatible clients - #2192
Open
bugprone wants to merge 1 commit into
Open
feat(ollama): add OpenAI- and Anthropic-compatible clients#2192bugprone wants to merge 1 commit into
bugprone wants to merge 1 commit into
Conversation
Ollama exposes three HTTP APIs; rig previously only spoke the native one. Following the zai/moonshot pattern of one typed client per API flavor, this adds ollama::OpenAiClient (/v1/chat/completions) and ollama::AnthropicClient (/v1/messages), both reusing the existing OpenAICompatibleProvider and AnthropicCompatibleProvider generic completion models. The native ollama::Client is unchanged and remains the default choice. The Messages API requires max_tokens, so the Anthropic-flavor client sends a default of 4096 when unset; this divergence is called out in the module docs. Base URL derivation tolerates OLLAMA_API_BASE_URL values that already carry the /v1 suffix, and a blank OLLAMA_API_KEY falls back to the placeholder the Anthropic layer requires. Part of 0xPlaygrounds#2156.
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.
Part of #2156, together with #2185 (which covers the native-payload
max_tokensfix). This adds the API-switching half discussed there.What
Ollama exposes three HTTP APIs: the native API, an OpenAI-compatible API, and an Anthropic-compatible API. rig previously only spoke the native one.
Following the same pattern zai and moonshot use for multiple API flavors (one typed client per flavor rather than a runtime switch), this adds:
ollama::OpenAiClient—/v1/chat/completions, reusingOpenAICompatibleProvider+ the generic OpenAI completion modelollama::AnthropicClient—/v1/messages, reusingAnthropicCompatibleProvider+ the generic Anthropic completion modelThe native
ollama::Clientis unchanged and documented as the default choice (it is the only flavor covering embeddings and model listing). No new request/response/streaming code — both clients ride the existing generic completion models.Notes
max_tokens(verified against a live Ollama), so the Anthropic-flavor client sends a default of 4096 when unset, matching zai/moonshot. The module docs call out this divergence from the other two flavors.OpenAiClient::from_envtolerates anOLLAMA_API_BASE_URLthat already carries the/v1suffix, and a blankOLLAMA_API_KEYfalls back to the placeholder value the Anthropic layer requires.Verification
All three clients verified against a live Ollama (qwen2.5:0.5b), including the
/v1-suffixed base URL and blank-API-key edge cases.cargo test -p rig-core --lib(1361 passed),cargo clippy --all-features --all-targets, andcargo fmt --checkare clean.