Module: Legion::Extensions::Llm::Ollama

Extended by:
AutoRegistration, Logging::Helper
Defined in:
lib/legion/extensions/llm/ollama.rb,
lib/legion/extensions/llm/ollama/version.rb,
lib/legion/extensions/llm/ollama/provider.rb,
lib/legion/extensions/llm/ollama/translator.rb,
lib/legion/extensions/llm/ollama/actors/discovery.rb,
lib/legion/extensions/llm/ollama/helpers/callable.rb,
lib/legion/extensions/llm/ollama/runners/discovery.rb,
lib/legion/extensions/llm/ollama/actors/fleet_worker.rb,
lib/legion/extensions/llm/ollama/runners/fleet_worker.rb

Overview

Ollama provider extension namespace.

Defined Under Namespace

Modules: Actor, Helpers, Runners Classes: Provider, Translator

Constant Summary collapse

PROVIDER_FAMILY =
:ollama
VERSION =
'0.3.7'

Class Method Summary collapse

Class Method Details

.claimable_instance_config(name:, config:) ⇒ Object

Only instances the operator actually configured are claimable. The synthetic instances.default section (provider_settings nests the extension's own instance defaults there) is skipped with a once-per-boot warn while it is still the unmodified extension default — an unconfigured phantom must never be auto-registered, and a localhost endpoint is never a fallback identity.



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/legion/extensions/llm/ollama.rb', line 72

def self.claimable_instance_config(name:, config:)
  return nil unless config.is_a?(Hash)

  normalized = normalize_instance_config(config)
  return nil if normalized[:enabled] == false

  unless normalized[:base_url].is_a?(String) && !normalized[:base_url].strip.empty?
    log.warn("[ollama][discovery] action=skip_instance instance=#{name} reason=missing_endpoint")
    return nil
  end

  normalized.merge(capabilities: {}, provider_capabilities: { streaming: true })
end

.configured_instancesObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/legion/extensions/llm/ollama.rb', line 52

def self.configured_instances
  instances = {}
  cfg_instances = CredentialSources.setting(:extensions, :llm, :ollama, :instances)
  return instances unless cfg_instances.is_a?(Hash)

  cfg_instances.each do |name, config|
    normalized = claimable_instance_config(name: name, config: config)
    instances[name.to_sym] = normalized unless normalized.nil?
  end

  log.debug { "ollama discovery returning instance_count=#{instances.size}" }
  instances
end

.default_settingsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/legion/extensions/llm/ollama.rb', line 21

def self.default_settings
  ::Legion::Extensions::Llm.provider_settings(
    family: PROVIDER_FAMILY,
    instance: {
      endpoint: 'http://127.0.0.1:11434',
      tier: :local,
      transport: :http,
      credentials: {},
      usage: { inference: true, image: false },
      limits: { concurrency: 1 },
      fleet: {
        enabled: false,
        respond_to_requests: false,
        capabilities: %i[chat stream_chat embed tools]
      }
    }
  )
end

.discover_instancesObject

Single source of truth for Ollama instance discovery. The SSOT discovery actor and the fleet responder both read this: only operator-configured instances, no port-scanning, no fabricated instances, no tier override.



48
49
50
# File 'lib/legion/extensions/llm/ollama.rb', line 48

def self.discover_instances
  configured_instances
end

.normalize_instance_config(config) ⇒ Object



100
101
102
103
104
105
106
107
# File 'lib/legion/extensions/llm/ollama.rb', line 100

def self.normalize_instance_config(config)
  normalized = config.to_h.transform_keys { |key| key.respond_to?(:to_sym) ? key.to_sym : key }
  normalized[:base_url] ||= normalized.delete(:ollama_api_base)
  normalized[:base_url] ||= normalized.delete(:api_base)
  normalized[:base_url] ||= normalized.delete(:endpoint)
  normalized[:tier] ||= :local
  normalized
end

.normalized_synthetic_default_instanceObject



94
95
96
97
98
# File 'lib/legion/extensions/llm/ollama.rb', line 94

def self.normalized_synthetic_default_instance
  @normalized_synthetic_default_instance ||= normalize_instance_config(
    default_settings.dig(:instances, :default) || {}
  )
end

.provider_classObject



40
41
42
# File 'lib/legion/extensions/llm/ollama.rb', line 40

def self.provider_class
  Provider
end

.unconfigured_default?(name:, normalized:) ⇒ Boolean

The synthetic default is the extension's OWN registered instance defaults (endpoint http://127.0.0.1:11434 + fleet/limits blocks), deep-merged into instances.default by provider_settings. It is "configured" only when the operator changed something.

Returns:

  • (Boolean)


90
91
92
# File 'lib/legion/extensions/llm/ollama.rb', line 90

def self.unconfigured_default?(name:, normalized:)
  name.to_sym == :default && normalized == normalized_synthetic_default_instance
end