Class: Legion::Extensions::Llm::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Logging::Helper
Includes:
Logging::Helper
Defined in:
lib/legion/extensions/llm/configuration.rb

Overview

Global configuration for Legion::Extensions::Llm

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



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

def initialize
  self.class.send(:defaults).each do |key, default|
    value = default.respond_to?(:call) ? instance_exec(&default) : default
    public_send("#{key}=", value)
  end
end

Class Method Details

.log_settings_defaultsObject

L5: the log defaults, read from the settings system (the ENV reads are deleted). A configured log_level Symbol/String names a Logger constant — an unknown name is a configuration error (it raises, it does not fall back).



35
36
37
38
39
40
# File 'lib/legion/extensions/llm/configuration.rb', line 35

def log_settings_defaults
  {
    level: log_level_value(llm_setting(:log_level)),
    stream_debug: llm_setting(:log_stream_debug) == true
  }
end

.option(key, default = nil) ⇒ Object

Declare a single configuration option.



12
13
14
15
16
17
18
19
# File 'lib/legion/extensions/llm/configuration.rb', line 12

def option(key, default = nil)
  key = key.to_sym
  return if options.include?(key)

  send(:attr_accessor, key)
  option_keys << key
  defaults[key] = default
end

.optionsObject



21
22
23
# File 'lib/legion/extensions/llm/configuration.rb', line 21

def options
  option_keys.dup
end

.register_provider_options(keys) ⇒ Object



25
26
27
# File 'lib/legion/extensions/llm/configuration.rb', line 25

def register_provider_options(keys)
  Array(keys).each { |key| option(key.to_sym) }
end

Instance Method Details

#instance_variablesObject



101
102
103
# File 'lib/legion/extensions/llm/configuration.rb', line 101

def instance_variables
  super.reject { |ivar| ivar.to_s.match?(/_id|_key|_secret|_token$/) }
end

#log_regexp_timeout=(value) ⇒ Object



105
106
107
108
109
110
111
112
113
114
# File 'lib/legion/extensions/llm/configuration.rb', line 105

def log_regexp_timeout=(value)
  if value.nil?
    @log_regexp_timeout = nil
  elsif Regexp.respond_to?(:timeout)
    @log_regexp_timeout = value
  else
    log.warn { "log_regexp_timeout is not supported on Ruby #{RUBY_VERSION}" }
    @log_regexp_timeout = value
  end
end