ollama build more customizable#9
Conversation
Signed-off-by: Aminu Oluwaseun Joshua <seun.aminujoshua@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR makes the Ollama provider client configuration more flexible by allowing the Ollama API base URL to be configured via an environment variable, rather than always using the default client settings.
Changes:
- Switch Ollama client initialization to use
Client::builder()instead ofClient::new(...). - Read
OLLAMA_API_BASE_URLfrom the environment with a localhost default.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let base_url = | ||
| std::env::var("OLLAMA_API_BASE_URL").unwrap_or("http://localhost:11434".to_string()); |
There was a problem hiding this comment.
std::env::var(...).unwrap_or("http://localhost:11434".to_string()) eagerly allocates the default String even when the env var is set. Prefer unwrap_or_else (or a const/Cow) so the default allocation only happens on the error path.
| let base_url = | |
| std::env::var("OLLAMA_API_BASE_URL").unwrap_or("http://localhost:11434".to_string()); | |
| let base_url = std::env::var("OLLAMA_API_BASE_URL") | |
| .unwrap_or_else(|_| "http://localhost:11434".to_string()); |
| let base_url = | ||
| std::env::var("OLLAMA_API_BASE_URL").unwrap_or("http://localhost:11434".to_string()); |
There was a problem hiding this comment.
std::env::var("OLLAMA_API_BASE_URL").unwrap_or(...) falls back to localhost for any VarError, including NotUnicode. That can silently ignore a misconfigured env var and be hard to diagnose. Consider only defaulting on VarError::NotPresent and returning an error for other cases.
| let base_url = | |
| std::env::var("OLLAMA_API_BASE_URL").unwrap_or("http://localhost:11434".to_string()); | |
| let base_url = match std::env::var("OLLAMA_API_BASE_URL") { | |
| Ok(base_url) => base_url, | |
| Err(std::env::VarError::NotPresent) => "http://localhost:11434".to_string(), | |
| Err(err) => return Err(err.into()), | |
| }; |
Signed-off-by: Aminu Oluwaseun Joshua <seun.aminujoshua@gmail.com>
Makes Ollama build more configurable, can get base_url via env