Skip to content

ollama_host

ollama_host

Normalize the Ollama server address read from OLLAMA_HOST or config.

Ollama's own CLI accepts OLLAMA_HOST=127.0.0.1:11434 with no scheme. OpenJarvis passes the value to httpx as a base URL, and httpx rejects a URL without http:// or https://. Every consumer therefore normalizes the host through this one function.

Functions

normalize_ollama_host

normalize_ollama_host(host: str) -> str

Return host as an HTTP base URL with no trailing slash.

A scheme is added when missing, so 127.0.0.1:11434 becomes http://127.0.0.1:11434. An empty string is returned unchanged so the caller can apply its own default.

Source code in src/openjarvis/core/ollama_host.py
def normalize_ollama_host(host: str) -> str:
    """Return ``host`` as an HTTP base URL with no trailing slash.

    A scheme is added when missing, so ``127.0.0.1:11434`` becomes
    ``http://127.0.0.1:11434``. An empty string is returned unchanged so the
    caller can apply its own default.
    """
    host = host.strip().rstrip("/")
    if host and "://" not in host:
        host = f"http://{host}"
    return host

ollama_host_from_env

ollama_host_from_env(default: str = DEFAULT_OLLAMA_HOST) -> str

Resolve the environment setting, using the default when it is blank.

Source code in src/openjarvis/core/ollama_host.py
def ollama_host_from_env(default: str = DEFAULT_OLLAMA_HOST) -> str:
    """Resolve the environment setting, using the default when it is blank."""
    return normalize_ollama_host(os.environ.get("OLLAMA_HOST", "")) or default