The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(custom): tolerate malformed ports in the Ollama URL heuristic
kshitijk4poorc87058983185
diff --git a/plugins/model-providers/custom/__init__.py b/plugins/model-providers/custom/__init__.pyindex 42b974d308e..fbe24be7a4a 100644--- a/plugins/model-providers/custom/__init__.py+++ b/plugins/model-providers/custom/__init__.py@@ -31,8 +31,16 @@ def _looks_like_ollama_endpoint(base_url: str | None) -> bool:if not raw:return Falseparsed = urlparse(raw if "://" in raw else f"//{raw}")- if parsed.port == 11434:- return True+ # urlparse raises ValueError for non-integer / out-of-range ports+ # ("http://host:99999/v1" parses fine in the OpenAI client, so the URL+ # is reachable here). Treat a malformed port as "not Ollama" instead of+ # killing the whole kwargs build — mirrors the same guard around the+ # 11434 check in hermes_cli/models.py should_use_ollama_native_catalog.+ try:+ if parsed.port == 11434:+ return True+ except ValueError:+ return Falsehost = (parsed.hostname or "").lower().rstrip(".")if not host:return Falsediff --git a/tests/plugins/model_providers/test_custom_profile.py b/tests/plugins/model_providers/test_custom_profile.pyindex 3774bb2ad89..72ca95f1cc0 100644--- a/tests/plugins/model_providers/test_custom_profile.py+++ b/tests/plugins/model_providers/test_custom_profile.py@@ -119,6 +119,30 @@ class TestCustomReasoningWireShape:assert eb == {"think": False}assert tl == {"reasoning_effort": "none"}+ @pytest.mark.parametrize(+ "base_url",+ [+ "http://myhost:99999/v1", # out-of-range port: OpenAI client accepts it+ "http://localhost:80a/v1", # non-integer port+ "http://localhost:11434./v1", # trailing-dot port+ ],+ )+ def test_malformed_port_does_not_raise(self, custom_profile, base_url):+ """Malformed ports must not raise — urlparse's ``port`` is ValueError-happy.++ The OpenAI client accepts ``http://myhost:99999/v1`` at construction+ (only httpx fails later), so these URLs reach ``build_api_kwargs_extras``+ in production. The heuristic must treat them as non-Ollama rather than+ killing the kwargs build.+ """+ eb, tl = custom_profile.build_api_kwargs_extras(+ reasoning_config={"enabled": False},+ model="qwen3",+ base_url=base_url,+ )+ assert "think" not in eb+ assert tl == {"reasoning_effort": "none"}+@pytest.mark.parametrize("effort", ["minimal", "low", "medium", "high", "xhigh", "max"])