fix: let saved Ollama URL override environment fallback

This commit is contained in:
Hermes Agent
2026-08-24 21:01:17 +10:00
parent d89251b5a8
commit 8ca332854f
4 changed files with 11 additions and 9 deletions
+8 -6
View File
@@ -305,11 +305,13 @@ def _write_connections(value: dict[str, str]) -> None:
def _apply_saved_connection() -> None:
global LOCAL_OLLAMA
if os.environ.get("OLLAMA_HOST", "").strip():
return
saved = _read_connections().get("active_url")
if saved:
LOCAL_OLLAMA = saved
return
configured = os.environ.get("OLLAMA_HOST", "").strip()
if configured:
LOCAL_OLLAMA = configured.rstrip("/")
def _target_endpoint(target: str = "local") -> str:
@@ -336,7 +338,7 @@ def _probe_endpoint(url: str, timeout: int = 5) -> dict[str, Any]:
def _connection_snapshot() -> list[dict[str, Any]]:
saved = _read_connections()
configured_local = os.environ.get("OLLAMA_HOST", "").strip() or saved.get("local_url")
configured_local = saved.get("local_url") or os.environ.get("OLLAMA_HOST", "").strip()
candidates: list[tuple[str, str, str]] = []
if configured_local:
candidates.append(("local", "Configured local endpoint", configured_local))
@@ -1475,7 +1477,7 @@ def chat(body: ChatRequest) -> dict[str, Any]:
@router.get("/connections")
def connections() -> dict[str, Any]:
saved = _read_connections()
active = os.environ.get("OLLAMA_HOST", "").strip() or saved.get("active_url") or LOCAL_OLLAMA
active = saved.get("active_url") or os.environ.get("OLLAMA_HOST", "").strip() or LOCAL_OLLAMA
return {"active_url": active, "connections": _connection_snapshot(), "containerized": _running_in_container()}
@@ -1494,10 +1496,10 @@ def connections_configure(body: ConnectionRequest) -> dict[str, Any]:
raise HTTPException(400, "Connection role must be local or remote")
saved = _read_connections()
saved[f"{role}_url"] = url
if role == "local" and not os.environ.get("OLLAMA_HOST", "").strip():
if role == "local":
saved["active_url"] = url
_write_connections(saved)
if role == "local" and not os.environ.get("OLLAMA_HOST", "").strip():
if role == "local":
global LOCAL_OLLAMA
LOCAL_OLLAMA = url
result = _probe_endpoint(url, timeout=8)