Class: Brute::Providers::Ollama

Inherits:
LLM::Ollama
  • Object
show all
Defined in:
lib/brute/providers/ollama.rb

Overview

Brute-level wrapper around LLM::Ollama for local model inference.

Adds environment-variable-based configuration so that all Brute examples and the CLI work out of the box with a local Ollama instance:

OLLAMA_HOST  — base URL (default: http://localhost:11434)
OLLAMA_MODEL — default model (default: llm.rb's default, currently qwen3:latest)

Examples:

Auto-detect via environment

export OLLAMA_HOST=http://localhost:11434
ruby examples/01_basic_agent.rb

Remote Ollama server

export OLLAMA_HOST=http://192.168.1.50:11434
export OLLAMA_MODEL=llama3.1:8b
ruby examples/02_fix_a_bug.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key: "none") ⇒ Ollama

Returns a new instance of Ollama.

Parameters:

  • key (String) (defaults to: "none")

    ignored (Ollama needs no auth), kept for provider interface



59
60
61
62
# File 'lib/brute/providers/ollama.rb', line 59

def initialize(key: "none", **)
  config = self.class.parse_host(ENV["OLLAMA_HOST"])
  super(key: key, host: config[:host], port: config[:port], ssl: config[:ssl], **)
end

Class Method Details

.parse_host(url) ⇒ Hash

Parse OLLAMA_HOST into host, port, and ssl components. Accepts formats like:

http://localhost:11434
https://ollama.example.com
192.168.1.50:11434
localhost

Parameters:

  • url (String, nil)

    raw OLLAMA_HOST value

Returns:

  • (Hash)

    with :host, :port, :ssl keys



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/brute/providers/ollama.rb', line 43

def self.parse_host(url)
  return { host: LLM::Ollama::HOST, port: 11434, ssl: false } if url.nil? || url.empty?

  # Prepend scheme if missing so URI.parse works
  url = "http://#{url}" unless url.match?(%r{\A\w+://})
  uri = URI.parse(url)

  {
    host: uri.host || LLM::Ollama::HOST,
    port: uri.port || 11434,
    ssl: uri.scheme == "https",
  }
end

Instance Method Details

#default_modelString

Returns the default model, preferring OLLAMA_MODEL env var.

Returns:

  • (String)


73
74
75
# File 'lib/brute/providers/ollama.rb', line 73

def default_model
  ENV["OLLAMA_MODEL"] || super
end

#nameSymbol

Returns:

  • (Symbol)


66
67
68
# File 'lib/brute/providers/ollama.rb', line 66

def name
  :ollama
end