feat(ollama): allow setting base_url and api_key programmatically#1511
Open
majiayu000 wants to merge 1 commit into0xPlaygrounds:mainfrom
Open
feat(ollama): allow setting base_url and api_key programmatically#1511majiayu000 wants to merge 1 commit into0xPlaygrounds:mainfrom
majiayu000 wants to merge 1 commit into0xPlaygrounds:mainfrom
Conversation
Add OllamaApiKey type that supports both unauthenticated (default) and Bearer token authenticated connections. This enables users to connect to multiple Ollama instances running on different servers with optional API key authentication for proxied deployments. The from_env() constructor now reads optional OLLAMA_API_KEY and defaults OLLAMA_API_BASE_URL to http://localhost:11434 instead of panicking when unset. Backward compatible: Client::new(Nothing) and .api_key(Nothing) still work via From<Nothing> for OllamaApiKey. Fixes 0xPlaygrounds#1070 Signed-off-by: majiayu000 <1835304752@qq.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
Allow users to configure
base_urlandapi_keyfor the Ollama provider programmatically, enabling support for multiple Ollama instances and proxied/authenticated deployments.Fixes #1070
Changes
OllamaApiKeytype with optional Bearer token auth (no auth by default)OllamaBuilder::ApiKeyfromNothingtoOllamaApiKeyfrom_env()now reads optionalOLLAMA_API_KEYenv var and defaultsOLLAMA_API_BASE_URLtohttp://localhost:11434(previously panicked when unset)From<Nothing>,From<String>,From<&str>for full backward compatibilityUsage:
Test plan
test_client_initializationwithNothing).api_key(Nothing)compile without changescargo fmtcleancargo clippyclean