Class: RubyLLM::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/configuration.rb

Overview

Global configuration for RubyLLM

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



72
73
74
75
76
77
# File 'lib/ruby_llm/configuration.rb', line 72

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

.option(key, default = nil) ⇒ Object

Declare a single configuration option.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ruby_llm/configuration.rb', line 10

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

  attr_reader key

  define_method("#{key}=") do |value|
    value = nil if value.is_a?(String) && value.strip.empty?
    instance_variable_set(:"@#{key}", value)
  end

  option_keys << key
  defaults[key] = default
end

.optionsObject



29
30
31
# File 'lib/ruby_llm/configuration.rb', line 29

def options
  option_keys.dup
end

.register_provider_options(options) ⇒ Object



25
26
27
# File 'lib/ruby_llm/configuration.rb', line 25

def register_provider_options(options)
  Array(options).each { |key| option(key, nil) }
end

Instance Method Details

#instance_variablesObject



79
80
81
# File 'lib/ruby_llm/configuration.rb', line 79

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

#log_regexp_timeout=(value) ⇒ Object



83
84
85
86
87
88
89
90
91
92
# File 'lib/ruby_llm/configuration.rb', line 83

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