Skip to content

fix: make OLLAMA_BASE_URL optional with sensible default#1755

Open
octo-patch wants to merge 6 commits into
assafelovic:mainfrom
octo-patch:fix/issue-1087-ollama-base-url-keyerror
Open

fix: make OLLAMA_BASE_URL optional with sensible default#1755
octo-patch wants to merge 6 commits into
assafelovic:mainfrom
octo-patch:fix/issue-1087-ollama-base-url-keyerror

Conversation

@octo-patch

Copy link
Copy Markdown
Contributor

Fixes #1087

Problem

base.py always reads os.environ["OLLAMA_BASE_URL"] with a hard dict
lookup, which raises KeyError for any user who runs Ollama on the
default localhost:11434 and hasn't set the environment variable.

A second related failure occurs when a caller already supplies base_url
in kwargs: the code also injects it from the env variable, causing
ChatOllama() got multiple values for keyword argument 'base_url'.

Both of these were reported in #1087.

Solution

  • Replace os.environ["OLLAMA_BASE_URL"] with
    os.environ.get("OLLAMA_BASE_URL", "http://localhost:11434") so users
    running a stock Ollama install get the correct default without setting
    any environment variable.
  • Only inject the base_url kwarg when the caller hasn't already
    supplied it, eliminating the "multiple values" error.
if "base_url" not in kwargs:
    kwargs["base_url"] = os.environ.get("OLLAMA_BASE_URL", "http://localhost:11434")

llm = ChatOllama(**kwargs)

Testing

  1. Without OLLAMA_BASE_URL: get_llm("ollama", model="llama3") no longer raises KeyError.
  2. With OLLAMA_BASE_URL: the env value is used as before.
  3. With explicit base_url in kwargs: no "multiple values" error.

adhikjoshi and others added 6 commits March 1, 2026 14:58
Adds ModelsLab as an alternative image generation provider alongside
the existing Google Gemini/Imagen provider.

ModelsLab (https://modelslab.com) provides access to Flux, SDXL,
Stable Diffusion, and 50k+ community models via a simple REST API.

Usage:
  export MODELSLAB_API_KEY=your_key
  # In config:
  IMAGE_GENERATION_ENABLED=true
  IMAGE_GENERATION_PROVIDER=modelslab
  IMAGE_GENERATION_MODEL=flux  # or sdxl, stable-diffusion-2-1, etc.

Changes:
- llm_provider/image/modelslab_image_generator.py: new ModelsLabImageGeneratorProvider
- llm_provider/image/__init__.py: export new class
- config/variables/base.py: add IMAGE_GENERATION_PROVIDER field
- config/variables/default.py: default provider is 'google' (backward compatible)
- skills/image_generator.py: select provider based on IMAGE_GENERATION_PROVIDER
…age-provider

feat: add ModelsLab image generation provider
When STRATEGIC_LLM env var is set without colon (e.g., 'gpt-4o'),
model_name is undefined, causing NameError.

Fix: assign strategic_llm directly to task['model'] in elif branch.

Fixes assafelovic#1673
fix: NameError when STRATEGIC_LLM lacks colon separator (assafelovic#1673)
…elovic#1087)

os.environ["OLLAMA_BASE_URL"] raised KeyError for users who hadn't set
the variable, crashing the Ollama provider before any LLM call was made.
Additionally, always passing base_url as a positional-style kwarg while
kwargs could also contain base_url caused "got multiple values for
keyword argument 'base_url'" errors when callers passed it explicitly.

Fix: use os.environ.get with "http://localhost:11434" as the default
(standard Ollama listen address) and only inject it when base_url is
not already present in kwargs.

Co-Authored-By: Octopus <liyuan851277048@icloud.com>
@assafelovic

Copy link
Copy Markdown
Owner

hey @octo-patch not sure why we need all that extra commits around images?

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.

Error When Running Ollama LLM Test Script for GPTR

4 participants