Module: Legion::Extensions::Llm::AutoRegistration
- Defined in:
- lib/legion/extensions/llm/auto_registration.rb
Overview
Mixin that lex-llm-* provider modules ‘extend` to get shared registration boilerplate. The provider only needs to override `discover_instances` — everything else is handled here.
Prerequisites on the extending module:
- `PROVIDER_FAMILY` constant (Symbol, e.g. :ollama)
- `provider_class` singleton method returning the Provider subclass
Instance Method Summary collapse
-
#discover_instances ⇒ Object
Override in each provider.
-
#rediscover! ⇒ Object
Deregisters all instances for this provider and re-runs discovery.
-
#register_discovered_instances ⇒ Object
Calls discover_instances, creates a LexLLMAdapter for each, and registers into Call::Registry.
Instance Method Details
#discover_instances ⇒ Object
Override in each provider. Returns { instance_id => config_hash }.
15 16 17 |
# File 'lib/legion/extensions/llm/auto_registration.rb', line 15 def discover_instances {} end |
#rediscover! ⇒ Object
Deregisters all instances for this provider and re-runs discovery.
Guarded: no-op when Legion::LLM::Call::Registry is not loaded.
46 47 48 49 50 51 |
# File 'lib/legion/extensions/llm/auto_registration.rb', line 46 def rediscover! return unless defined?(Legion::LLM::Call::Registry) Legion::LLM::Call::Registry.deregister_provider(self::PROVIDER_FAMILY) register_discovered_instances end |
#register_discovered_instances ⇒ Object
Calls discover_instances, creates a LexLLMAdapter for each, and registers into Call::Registry.
Strips :tier and :capabilities from config before passing to the adapter (these are metadata, not connection config).
Guarded: no-op when Legion::LLM::Call::Registry is not loaded.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/legion/extensions/llm/auto_registration.rb', line 26 def register_discovered_instances return unless defined?(Legion::LLM::Call::Registry) instances = discover_instances instances.each do |instance_id, config| registry_config = config.except(:tier, :capabilities) adapter = Legion::LLM::Call::LexLLMAdapter.new( self::PROVIDER_FAMILY, provider_class, instance_config: registry_config ) Legion::LLM::Call::Registry.register( self::PROVIDER_FAMILY, adapter, instance: instance_id ) end rescue StandardError => e log.warn "[#{self::PROVIDER_FAMILY}] self-registration failed: #{e.}" if respond_to?(:log) end |