Skip to content

fix(llm): fall back to OLLAMA_HOST when OLLAMA_BASE_URL is unset#2019

Open
kimdzhekhon wants to merge 1 commit into
Graphify-Labs:v8from
kimdzhekhon:fix/ollama-host-env-fallback-1940
Open

fix(llm): fall back to OLLAMA_HOST when OLLAMA_BASE_URL is unset#2019
kimdzhekhon wants to merge 1 commit into
Graphify-Labs:v8from
kimdzhekhon:fix/ollama-host-env-fallback-1940

Conversation

@kimdzhekhon

Copy link
Copy Markdown

Summary

  • Ollama's own server has no OLLAMA_BASE_URL concept — its documented config var is OLLAMA_HOST (Ollama FAQ). graphify only ever read OLLAMA_BASE_URL, so a user who configured Ollama the way its own docs describe got silently routed to the localhost:11434 default instead.
  • Adds _resolve_ollama_base_url(default): OLLAMA_BASE_URL still wins when set (unchanged behavior — this mirrors graphify's existing per-backend *_BASE_URL override convention, e.g. KIMI_BASE_URL, GEMINI_BASE_URL, left untouched). Otherwise falls back to OLLAMA_HOST, normalized into an OpenAI-compatible URL: adds http:// if no scheme is present, ensures a trailing /v1 (no duplication if already present).
  • Wired into all 3 read sites: the BACKENDS["ollama"]["base_url"] dict-literal default and the two ollama_url = os.environ.get("OLLAMA_BASE_URL", ...) call sites.

Fixes #1940.

Test plan

  • Added 4 tests in tests/test_llm_backends.py: OLLAMA_BASE_URL takes priority over OLLAMA_HOST; scheme-less OLLAMA_HOST gets http:// + /v1; an already-normalized OLLAMA_HOST (scheme + /v1) passes through unchanged; neither set → falls back to caller's default
  • uv run pytest tests/test_llm_backends.py -q -k ollama — 13 passed
  • uv run pytest tests/ -q — full suite: 3415 passed (5 pre-existing failures unrelated to this change, missing optional openai dependency in this environment)

Ollama's own server has no OLLAMA_BASE_URL concept — it reads
OLLAMA_HOST (https://docs.ollama.com/faq#how-do-i-configure-ollama-server).
graphify only ever read OLLAMA_BASE_URL, so anyone who configured Ollama
the way its own docs describe (OLLAMA_HOST) had graphify silently ignore
it and fall back to the localhost:11434 default.

Add _resolve_ollama_base_url(default): OLLAMA_BASE_URL still wins when
set (unchanged behavior, graphify's existing convention for OpenAI-
compatible base_url overrides across backends). Otherwise falls back to
OLLAMA_HOST, normalized into an OpenAI-compatible URL (adds a scheme if
missing, ensures a trailing /v1). Wired into the BACKENDS dict's ollama
entry and the two ollama_url call sites that read the env var directly.

Fixes Graphify-Labs#1940.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Env var OLLAMA_BASE_URL is inconsistent with actual Ollama-held env var name

1 participant