fix(llm): Properly detect remote Ollama bare URLs as native endpoints (fixes #3252) (#3343)

This commit is contained in:
adabarbulescu
2026-06-07 22:19:19 +03:00
committed by GitHub
parent 6c9a16a7a8
commit a8859bb25c
2 changed files with 18 additions and 2 deletions
+5 -1
View File
@@ -270,8 +270,10 @@ def _is_ollama_native_url(url: str) -> bool:
path = (parsed.path or "").rstrip("/")
if _host_match(url, "ollama.com"):
return True
if path.startswith("/v1"):
return False
local_ollama_host = host in {"localhost", "127.0.0.1", "0.0.0.0", "::1"} or parsed.port == 11434
return local_ollama_host and (path == "/api" or path.startswith("/api/"))
return local_ollama_host and (path == "" or path == "/api" or path.startswith("/api/"))
def _ollama_api_root(url: str) -> str:
@@ -287,6 +289,8 @@ def _ollama_api_root(url: str) -> str:
return url[: -len("/generate")]
if path.endswith("/api"):
return url
if path == "":
return url + "/api"
if _host_match(url, "ollama.com"):
root = f"{parsed.scheme}://{parsed.netloc}" if parsed.scheme and parsed.netloc else "https://ollama.com"
return root.rstrip("/") + "/api"