Class: Sloprb::Configuration
- Inherits:
-
Object
- Object
- Sloprb::Configuration
- Defined in:
- lib/sloprb/configuration.rb
Constant Summary collapse
- PROVIDERS =
[ [:openai, ->(env) { env["OPENAI_API_KEY"] }, ->(env) { {openai_api_key: env["OPENAI_API_KEY"]} }], [:anthropic, ->(env) { env["ANTHROPIC_API_KEY"] }, ->(env) { {anthropic_api_key: env["ANTHROPIC_API_KEY"]} }], [:ollama, ->(env) { env["OLLAMA_BASE_URL"] }, ->(env) { base = env["OLLAMA_BASE_URL"].chomp("/") base += "/v1" unless base.end_with?("/v1") {openai_api_key: "ollama", ollama_api_base: base} }] ].freeze
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Instance Method Summary collapse
- #configure_ruby_llm! ⇒ Object
- #ensure_ruby_llm_configured! ⇒ Object
-
#initialize(env = ENV) ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize(env = ENV) ⇒ Configuration
Returns a new instance of Configuration.
21 22 23 24 25 26 |
# File 'lib/sloprb/configuration.rb', line 21 def initialize(env = ENV) @env = env @provider, @config = detect_provider(env) @model = env.fetch("SLOPRB_MODEL") { default_model } @configured = false end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
19 20 21 |
# File 'lib/sloprb/configuration.rb', line 19 def model @model end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
19 20 21 |
# File 'lib/sloprb/configuration.rb', line 19 def provider @provider end |
Instance Method Details
#configure_ruby_llm! ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/sloprb/configuration.rb', line 28 def configure_ruby_llm! raise "sloprb: SLOPRB_MODEL is required for the #{@provider} provider." unless @model RubyLLM.configure do |c| @config.each { |k, v| c.public_send(:"#{k}=", v) } c.log_level = :unknown unless @env["SLOPRB_DEBUG"] end end |
#ensure_ruby_llm_configured! ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sloprb/configuration.rb', line 37 def ensure_ruby_llm_configured! return if @configured raise "sloprb: No LLM provider configured. Set OPENAI_API_KEY, ANTHROPIC_API_KEY, or OLLAMA_BASE_URL." unless @provider @configured = true configure_ruby_llm! RubyLLM::Models.refresh! if provider == :ollama end |