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/fleet_worker.rb,
lib/legion/extensions/llm/ollama/runners/fleet_worker.rb,
lib/legion/extensions/llm/ollama/actors/discovery_refresh.rb
Overview
Ollama provider extension namespace.
Defined Under Namespace
Modules: Actor, Runners
Classes: Provider, Translator
Constant Summary
collapse
- PROVIDER_FAMILY =
:ollama
- VERSION =
'0.3.4'
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.
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/legion/extensions/llm/ollama.rb', line 75
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
|
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/legion/extensions/llm/ollama.rb', line 55
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_settings ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/legion/extensions/llm/ollama.rb', line 20
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_instances ⇒ Object
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.
51
52
53
|
# File 'lib/legion/extensions/llm/ollama.rb', line 51
def self.discover_instances
configured_instances
end
|
.normalize_instance_config(config) ⇒ Object
103
104
105
106
107
108
109
110
|
# File 'lib/legion/extensions/llm/ollama.rb', line 103
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_instance ⇒ Object
97
98
99
100
101
|
# File 'lib/legion/extensions/llm/ollama.rb', line 97
def self.normalized_synthetic_default_instance
@normalized_synthetic_default_instance ||= normalize_instance_config(
default_settings.dig(:instances, :default) || {}
)
end
|
.provider_class ⇒ Object
39
40
41
|
# File 'lib/legion/extensions/llm/ollama.rb', line 39
def self.provider_class
Provider
end
|
.registry_publisher ⇒ Object
43
44
45
|
# File 'lib/legion/extensions/llm/ollama.rb', line 43
def self.registry_publisher
@registry_publisher ||= Legion::Extensions::Llm::RegistryPublisher.new(provider_family: PROVIDER_FAMILY)
end
|
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.
93
94
95
|
# File 'lib/legion/extensions/llm/ollama.rb', line 93
def self.unconfigured_default?(name:, normalized:)
name.to_sym == :default && normalized == normalized_synthetic_default_instance
end
|