Class: Mana::Config
- Inherits:
-
Object
- Object
- Mana::Config
- Defined in:
- lib/mana/config.rb
Overview
Central configuration for Mana. Set via Mana.configure { |c| ... }.
Key options:
model - LLM model name (default: claude-sonnet-4-6)
api_key - API key, falls back to ANTHROPIC_API_KEY or OPENAI_API_KEY env vars
base_url - Custom API endpoint, falls back to ANTHROPIC_API_URL or OPENAI_API_URL
backend - :anthropic, :openai, or nil (auto-detect from model name)
timeout - HTTP timeout in seconds (default: 120)
Constant Summary collapse
- DEFAULT_ANTHROPIC_URL =
"https://api.anthropic.com"- DEFAULT_OPENAI_URL =
"https://api.openai.com"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#backend ⇒ Object
Returns the value of attribute backend.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#context_class ⇒ Object
(also: #memory_class)
Returns the value of attribute context_class.
-
#context_window ⇒ Object
Returns the value of attribute context_window.
-
#knowledge_provider ⇒ Object
Returns the value of attribute knowledge_provider.
-
#max_iterations ⇒ Object
Returns the value of attribute max_iterations.
-
#memory_path ⇒ Object
Returns the value of attribute memory_path.
-
#memory_store ⇒ Object
Returns the value of attribute memory_store.
-
#model ⇒ Object
Returns the value of attribute model.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#temperature ⇒ Object
Returns the value of attribute temperature.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#effective_base_url ⇒ Object
Resolve the effective base URL based on the configured or auto-detected backend.
-
#initialize ⇒ Config
constructor
All config options can be set via environment variables: MANA_MODEL, MANA_VERBOSE, MANA_TIMEOUT, MANA_BACKEND ANTHROPIC_API_KEY / OPENAI_API_KEY ANTHROPIC_API_URL / OPENAI_API_URL.
-
#validate! ⇒ Object
Validate configuration and raise early if something is wrong.
Constructor Details
#initialize ⇒ Config
All config options can be set via environment variables:
MANA_MODEL, MANA_VERBOSE, MANA_TIMEOUT, MANA_BACKEND
ANTHROPIC_API_KEY / OPENAI_API_KEY
ANTHROPIC_API_URL / OPENAI_API_URL
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mana/config.rb', line 31 def initialize @model = ENV["MANA_MODEL"] || "claude-sonnet-4-6" @temperature = 0 @api_key = ENV["ANTHROPIC_API_KEY"] || ENV["OPENAI_API_KEY"] @max_iterations = 50 @base_url = ENV["ANTHROPIC_API_URL"] || ENV["OPENAI_API_URL"] self.timeout = (ENV["MANA_TIMEOUT"] || 120).to_i @verbose = %w[1 true yes].include?(ENV["MANA_VERBOSE"]&.downcase) @backend = ENV["MANA_BACKEND"]&.to_sym @namespace = nil @memory_store = nil @memory_path = nil @context_window = 128_000 @context_class = nil # nil = use Mana::Context; set to custom class @knowledge_provider = nil # nil = use Mana::Knowledge; set to custom module with .query(topic) end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
13 14 15 |
# File 'lib/mana/config.rb', line 13 def api_key @api_key end |
#backend ⇒ Object
Returns the value of attribute backend.
13 14 15 |
# File 'lib/mana/config.rb', line 13 def backend @backend end |
#base_url ⇒ Object
Returns the value of attribute base_url.
13 14 15 |
# File 'lib/mana/config.rb', line 13 def base_url @base_url end |
#context_class ⇒ Object Also known as: memory_class
Returns the value of attribute context_class.
13 14 15 |
# File 'lib/mana/config.rb', line 13 def context_class @context_class end |
#context_window ⇒ Object
Returns the value of attribute context_window.
13 14 15 |
# File 'lib/mana/config.rb', line 13 def context_window @context_window end |
#knowledge_provider ⇒ Object
Returns the value of attribute knowledge_provider.
13 14 15 |
# File 'lib/mana/config.rb', line 13 def knowledge_provider @knowledge_provider end |
#max_iterations ⇒ Object
Returns the value of attribute max_iterations.
13 14 15 |
# File 'lib/mana/config.rb', line 13 def max_iterations @max_iterations end |
#memory_path ⇒ Object
Returns the value of attribute memory_path.
13 14 15 |
# File 'lib/mana/config.rb', line 13 def memory_path @memory_path end |
#memory_store ⇒ Object
Returns the value of attribute memory_store.
13 14 15 |
# File 'lib/mana/config.rb', line 13 def memory_store @memory_store end |
#model ⇒ Object
Returns the value of attribute model.
13 14 15 |
# File 'lib/mana/config.rb', line 13 def model @model end |
#namespace ⇒ Object
Returns the value of attribute namespace.
13 14 15 |
# File 'lib/mana/config.rb', line 13 def namespace @namespace end |
#temperature ⇒ Object
Returns the value of attribute temperature.
13 14 15 |
# File 'lib/mana/config.rb', line 13 def temperature @temperature end |
#timeout ⇒ Object
Returns the value of attribute timeout.
18 19 20 |
# File 'lib/mana/config.rb', line 18 def timeout @timeout end |
#verbose ⇒ Object
Returns the value of attribute verbose.
13 14 15 |
# File 'lib/mana/config.rb', line 13 def verbose @verbose end |
Instance Method Details
#effective_base_url ⇒ Object
Resolve the effective base URL based on the configured or auto-detected backend. Falls back to the appropriate default when no explicit URL is set.
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/mana/config.rb', line 59 def effective_base_url # Return user-configured URL if explicitly set return @base_url if @base_url # Otherwise pick the default URL based on backend type if anthropic_backend? DEFAULT_ANTHROPIC_URL else DEFAULT_OPENAI_URL end end |
#validate! ⇒ Object
Validate configuration and raise early if something is wrong. Called automatically by Mana.configure, or manually via Mana.config.validate!
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/mana/config.rb', line 73 def validate! if @api_key.nil? || @api_key.to_s.strip.empty? raise ConfigError, "API key is not configured. Set it via environment variable or Mana.configure:\n\n" \ " export ANTHROPIC_API_KEY=your_key_here\n" \ " # or\n" \ " export OPENAI_API_KEY=your_key_here\n" \ " # or\n" \ " Mana.configure { |c| c.api_key = \"your_key_here\" }\n" end true end |