Class: Llm::Config
- Inherits:
-
Object
- Object
- Llm::Config
- Defined in:
- lib/llm/config.rb
Overview
Reads LLM configuration from env vars and config/config.yml Env vars take precedence over config file values.
Constant Summary collapse
- PROVIDERS =
%w[openai anthropic ollama].freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#provider_name ⇒ Object
readonly
Returns the value of attribute provider_name.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #build_provider ⇒ Object
- #configured? ⇒ Boolean
-
#initialize ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
13 14 15 16 17 18 |
# File 'lib/llm/config.rb', line 13 def initialize @provider_name = env('RUBY_RAIDER_LLM_PROVIDER') || config_value('llm_provider') @api_key = env('RUBY_RAIDER_LLM_API_KEY') || config_value('llm_api_key') @model = env('RUBY_RAIDER_LLM_MODEL') || config_value('llm_model') @url = env('RUBY_RAIDER_LLM_URL') || config_value('llm_url') end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
11 12 13 |
# File 'lib/llm/config.rb', line 11 def api_key @api_key end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
11 12 13 |
# File 'lib/llm/config.rb', line 11 def model @model end |
#provider_name ⇒ Object (readonly)
Returns the value of attribute provider_name.
11 12 13 |
# File 'lib/llm/config.rb', line 11 def provider_name @provider_name end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
11 12 13 |
# File 'lib/llm/config.rb', line 11 def url @url end |
Instance Method Details
#build_provider ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/llm/config.rb', line 27 def build_provider return nil unless configured? case @provider_name when 'openai' require_relative 'providers/openai_provider' Providers::OpenaiProvider.new(api_key: @api_key, model: @model) when 'anthropic' require_relative 'providers/anthropic_provider' Providers::AnthropicProvider.new(api_key: @api_key, model: @model) when 'ollama' require_relative 'providers/ollama_provider' Providers::OllamaProvider.new(model: @model, url: @url) end end |
#configured? ⇒ Boolean
20 21 22 23 24 25 |
# File 'lib/llm/config.rb', line 20 def configured? return false unless @provider_name && PROVIDERS.include?(@provider_name) return true if @provider_name == 'ollama' !@api_key.nil? && !@api_key.empty? end |