Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions crates/goose/src/providers/ollama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ impl OllamaProvider {

// Set the default port if missing
// Don't add default port if:
// 1. URL explicitly ends with standard ports (:80 or :443)
// 2. URL uses HTTPS (which implicitly uses port 443)
let explicit_default_port = host.ends_with(":80") || host.ends_with(":443");
let is_https = base_url.scheme() == "https";

if base_url.port().is_none() && !explicit_default_port && !is_https {
// 1. URL/host explicitly contains ports
// 2. URL/host uses HTTP/S
// 3. only set it for localhost
let explicit_port = host.contains(':');
let is_localhost = host == "localhost" || host == "127.0.0.1" || host == "::1";

if base_url.port().is_none() && !explicit_port && !host.starts_with("http") && is_localhost
{
base_url
.set_port(Some(OLLAMA_DEFAULT_PORT))
.map_err(|_| anyhow::anyhow!("Failed to set default port"))?;
Expand Down
Loading