feat: support physical and Docker Ollama runtimes
This commit is contained in:
+28
-2
@@ -31,7 +31,20 @@ from pydantic import BaseModel, Field
|
||||
from hermes_constants import get_hermes_home
|
||||
|
||||
router = APIRouter()
|
||||
LOCAL_OLLAMA = os.environ.get("OLLAMA_HOST", "http://localhost:11434").rstrip("/")
|
||||
|
||||
|
||||
def _running_in_container() -> bool:
|
||||
return Path("/.dockerenv").exists() or Path("/run/.containerenv").exists()
|
||||
|
||||
|
||||
def _ollama_base_url() -> str:
|
||||
configured = os.environ.get("OLLAMA_HOST", "").strip()
|
||||
if configured:
|
||||
return configured.rstrip("/")
|
||||
return "http://ollama:11434" if _running_in_container() else "http://localhost:11434"
|
||||
|
||||
|
||||
LOCAL_OLLAMA = _ollama_base_url()
|
||||
REMOTE_OLLAMA = "https://ollama.com"
|
||||
CATALOG_FILE = "catalog.json"
|
||||
MODEL_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._:/-]{0,190}$")
|
||||
@@ -1396,8 +1409,21 @@ def status() -> dict[str, Any]:
|
||||
variants.append(variant)
|
||||
row["variants"] = sorted(variants, key=lambda item: (item.get("size_bytes") or 0, item["name"]))
|
||||
|
||||
ollama_version = _ollama_version()
|
||||
return {
|
||||
"ollama": {"available": bool(tags or ps_rows), "version": _ollama_version(), "endpoint": LOCAL_OLLAMA},
|
||||
"ollama": {
|
||||
"available": bool(tags or ps_rows or ollama_version),
|
||||
"version": ollama_version,
|
||||
"endpoint": LOCAL_OLLAMA,
|
||||
"containerized": _running_in_container(),
|
||||
"configured_endpoint": bool(os.environ.get("OLLAMA_HOST", "").strip()),
|
||||
"connection_hint": (
|
||||
"Set OLLAMA_HOST to a reachable Ollama service, such as "
|
||||
"http://ollama:11434 or http://host.docker.internal:11434."
|
||||
if _running_in_container() and not (tags or ps_rows or ollama_version)
|
||||
else ""
|
||||
),
|
||||
},
|
||||
"models": local,
|
||||
"popular": popular,
|
||||
"popular_filter": {
|
||||
|
||||
Reference in New Issue
Block a user