Class: RubyCanUseLLM::Configuration

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

Constant Summary collapse

SUPPORTED_PROVIDERS =
%i[openai anthropic voyage mistral ollama].freeze
EMBEDDING_PROVIDERS =
%i[openai voyage mistral ollama].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



10
11
12
13
14
15
16
17
18
# File 'lib/rubycanusellm/configuration.rb', line 10

def initialize
  @provider = nil
  @api_key = nil
  @model = nil
  @timeout = 30
  @embedding_provider = nil
  @embedding_api_key = nil
  @base_url = nil
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



8
9
10
# File 'lib/rubycanusellm/configuration.rb', line 8

def api_key
  @api_key
end

#base_urlObject

Returns the value of attribute base_url.



8
9
10
# File 'lib/rubycanusellm/configuration.rb', line 8

def base_url
  @base_url
end

#embedding_api_keyObject

Returns the value of attribute embedding_api_key.



8
9
10
# File 'lib/rubycanusellm/configuration.rb', line 8

def embedding_api_key
  @embedding_api_key
end

#embedding_providerObject

Returns the value of attribute embedding_provider.



8
9
10
# File 'lib/rubycanusellm/configuration.rb', line 8

def embedding_provider
  @embedding_provider
end

#modelObject

Returns the value of attribute model.



8
9
10
# File 'lib/rubycanusellm/configuration.rb', line 8

def model
  @model
end

#providerObject

Returns the value of attribute provider.



8
9
10
# File 'lib/rubycanusellm/configuration.rb', line 8

def provider
  @provider
end

#timeoutObject

Returns the value of attribute timeout.



8
9
10
# File 'lib/rubycanusellm/configuration.rb', line 8

def timeout
  @timeout
end

Instance Method Details

#validate!Object

Raises:



20
21
22
23
24
25
26
27
28
# File 'lib/rubycanusellm/configuration.rb', line 20

def validate!
  raise Error, "provider is required. Use :openai, :anthropic, :mistral, or :ollama" if provider.nil?

  raise Error, "api_key is required" if provider != :ollama && (api_key.nil? || api_key.empty?)
  return if SUPPORTED_PROVIDERS.include?(provider)

  raise Error,
        "Unknown provider: #{provider}. Supported: #{SUPPORTED_PROVIDERS.join(", ")}"
end

#validate_embedding!Object

Raises:



30
31
32
33
34
35
36
37
38
39
# File 'lib/rubycanusellm/configuration.rb', line 30

def validate_embedding!
  effective = embedding_provider || provider
  unless EMBEDDING_PROVIDERS.include?(effective)
    raise Error,
          "#{provider} does not support embeddings. Set config.embedding_provider to :openai or :voyage and provide config.embedding_api_key"
  end
  return unless embedding_provider && (embedding_api_key.nil? || embedding_api_key.empty?)

  raise Error, "embedding_api_key is required when embedding_provider is set"
end