Class: LlmOptimizer::Configuration
- Inherits:
-
Object
- Object
- LlmOptimizer::Configuration
- Defined in:
- lib/llm_optimizer/configuration.rb
Constant Summary collapse
- KNOWN_KEYS =
%i[ use_semantic_cache compress_prompt manage_history route_to similarity_threshold token_budget redis_url embedding_model simple_model complex_model logger debug_logging timeout_seconds cache_ttl llm_caller embedding_caller classifier_caller conversation_ttl system_prompt messages_caller ].freeze
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#merge!(other_config) ⇒ Object
Copies only explicitly set keys from other_config without resetting unmentioned keys.
- #method_missing(name, *args) ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/llm_optimizer/configuration.rb', line 33 def initialize @explicitly_set = Set.new @use_semantic_cache = false @compress_prompt = false @manage_history = false @route_to = :auto @similarity_threshold = 0.96 @token_budget = 4000 @redis_url = nil @embedding_model = "text-embedding-3-small" @simple_model = "gpt-4o-mini" @complex_model = "claude-3-5-sonnet-20241022" @logger = Logger.new($stdout) @debug_logging = false @timeout_seconds = 5 @cache_ttl = 86_400 @llm_caller = nil @embedding_caller = nil @classifier_caller = nil @conversation_ttl = 86_400 @system_prompt = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/llm_optimizer/configuration.rb', line 65 def method_missing(name, *args, &) key = name.to_s.chomp("=").to_sym raise ConfigurationError, "Unknown configuration key: #{key}" unless KNOWN_KEYS.include?(key) super end |
Instance Method Details
#merge!(other_config) ⇒ Object
Copies only explicitly set keys from other_config without resetting unmentioned keys.
58 59 60 61 62 63 |
# File 'lib/llm_optimizer/configuration.rb', line 58 def merge!(other_config) other_config.instance_variable_get(:@explicitly_set).each do |key| public_send(:"#{key}=", other_config.public_send(key)) end self end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
72 73 74 75 |
# File 'lib/llm_optimizer/configuration.rb', line 72 def respond_to_missing?(name, include_private = false) key = name.to_s.chomp("=").to_sym KNOWN_KEYS.include?(key) || super end |