fit: default ollama port (#4001)

This commit is contained in:
Michael Neale
2025-08-12 12:16:31 +10:00
committed by GitHub
parent dd504741a3
commit 168366be3b
+7 -5
View File
@@ -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";
// 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_default_port && !is_https {
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"))?;