Class: Ace::LLM::Models::FallbackConfig
- Inherits:
-
Object
- Object
- Ace::LLM::Models::FallbackConfig
- Defined in:
- lib/ace/llm/models/fallback_config.rb
Overview
FallbackConfig represents fallback configuration settings This is a model - pure data structure with validation
Constant Summary collapse
- DEFAULT_ENABLED =
Default configuration values
true- DEFAULT_RETRY_COUNT =
3- DEFAULT_RETRY_DELAY =
1.0- DEFAULT_PROVIDERS =
[].freeze
- DEFAULT_CHAINS =
{}.freeze
- DEFAULT_MAX_TOTAL_TIMEOUT =
30.0
Instance Attribute Summary collapse
-
#chains ⇒ Object
readonly
Returns the value of attribute chains.
-
#enabled ⇒ Object
readonly
Returns the value of attribute enabled.
-
#max_total_timeout ⇒ Object
readonly
Returns the value of attribute max_total_timeout.
-
#providers ⇒ Object
readonly
Returns the value of attribute providers.
-
#retry_count ⇒ Object
readonly
Returns the value of attribute retry_count.
-
#retry_delay ⇒ Object
readonly
Returns the value of attribute retry_delay.
Class Method Summary collapse
-
.fetch_key(hash, key, default) ⇒ Object
Helper to fetch key from hash supporting both symbol and string keys.
-
.from_hash(hash) ⇒ FallbackConfig
Create FallbackConfig from a hash (e.g., from YAML).
Instance Method Summary collapse
-
#disabled? ⇒ Boolean
Check if fallback is disabled.
-
#enabled? ⇒ Boolean
Check if fallback is enabled.
-
#has_providers? ⇒ Boolean
Check if there are any fallback providers configured.
-
#initialize(enabled: DEFAULT_ENABLED, retry_count: DEFAULT_RETRY_COUNT, retry_delay: DEFAULT_RETRY_DELAY, providers: DEFAULT_PROVIDERS, chains: DEFAULT_CHAINS, max_total_timeout: DEFAULT_MAX_TOTAL_TIMEOUT) ⇒ FallbackConfig
constructor
A new instance of FallbackConfig.
-
#merge(other) ⇒ FallbackConfig
Merge with another config (other takes precedence).
-
#providers_for(primary) ⇒ Array<String>
Return fallback providers for a specific primary provider Uses per-provider chain if configured, otherwise falls back to default providers.
-
#to_h ⇒ Hash
Convert to hash representation.
Constructor Details
#initialize(enabled: DEFAULT_ENABLED, retry_count: DEFAULT_RETRY_COUNT, retry_delay: DEFAULT_RETRY_DELAY, providers: DEFAULT_PROVIDERS, chains: DEFAULT_CHAINS, max_total_timeout: DEFAULT_MAX_TOTAL_TIMEOUT) ⇒ FallbackConfig
Returns a new instance of FallbackConfig.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ace/llm/models/fallback_config.rb', line 25 def initialize(enabled: DEFAULT_ENABLED, retry_count: DEFAULT_RETRY_COUNT, retry_delay: DEFAULT_RETRY_DELAY, providers: DEFAULT_PROVIDERS, chains: DEFAULT_CHAINS, max_total_timeout: DEFAULT_MAX_TOTAL_TIMEOUT) @enabled = enabled @retry_count = retry_count @retry_delay = retry_delay @providers = providers.freeze @chains = chains @max_total_timeout = max_total_timeout validate! @chains = normalize_chains(@chains).freeze end |
Instance Attribute Details
#chains ⇒ Object (readonly)
Returns the value of attribute chains.
9 10 11 |
# File 'lib/ace/llm/models/fallback_config.rb', line 9 def chains @chains end |
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled.
9 10 11 |
# File 'lib/ace/llm/models/fallback_config.rb', line 9 def enabled @enabled end |
#max_total_timeout ⇒ Object (readonly)
Returns the value of attribute max_total_timeout.
9 10 11 |
# File 'lib/ace/llm/models/fallback_config.rb', line 9 def max_total_timeout @max_total_timeout end |
#providers ⇒ Object (readonly)
Returns the value of attribute providers.
9 10 11 |
# File 'lib/ace/llm/models/fallback_config.rb', line 9 def providers @providers end |
#retry_count ⇒ Object (readonly)
Returns the value of attribute retry_count.
9 10 11 |
# File 'lib/ace/llm/models/fallback_config.rb', line 9 def retry_count @retry_count end |
#retry_delay ⇒ Object (readonly)
Returns the value of attribute retry_delay.
9 10 11 |
# File 'lib/ace/llm/models/fallback_config.rb', line 9 def retry_delay @retry_delay end |
Class Method Details
.fetch_key(hash, key, default) ⇒ Object
Helper to fetch key from hash supporting both symbol and string keys
127 128 129 |
# File 'lib/ace/llm/models/fallback_config.rb', line 127 def self.fetch_key(hash, key, default) hash.fetch(key, hash.fetch(key.to_s, default)) end |
.from_hash(hash) ⇒ FallbackConfig
Create FallbackConfig from a hash (e.g., from YAML)
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ace/llm/models/fallback_config.rb', line 46 def self.from_hash(hash) return new unless hash new( enabled: fetch_key(hash, :enabled, DEFAULT_ENABLED), retry_count: fetch_key(hash, :retry_count, DEFAULT_RETRY_COUNT), retry_delay: fetch_key(hash, :retry_delay, DEFAULT_RETRY_DELAY), providers: fetch_key(hash, :providers, DEFAULT_PROVIDERS), chains: fetch_key(hash, :chains, DEFAULT_CHAINS), max_total_timeout: fetch_key(hash, :max_total_timeout, DEFAULT_MAX_TOTAL_TIMEOUT) ) end |
Instance Method Details
#disabled? ⇒ Boolean
Check if fallback is disabled
89 90 91 |
# File 'lib/ace/llm/models/fallback_config.rb', line 89 def disabled? !enabled? end |
#enabled? ⇒ Boolean
Check if fallback is enabled
83 84 85 |
# File 'lib/ace/llm/models/fallback_config.rb', line 83 def enabled? @enabled == true end |
#has_providers? ⇒ Boolean
Check if there are any fallback providers configured
95 96 97 |
# File 'lib/ace/llm/models/fallback_config.rb', line 95 def has_providers? @providers && !@providers.empty? end |
#merge(other) ⇒ FallbackConfig
Merge with another config (other takes precedence)
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ace/llm/models/fallback_config.rb', line 102 def merge(other) other_hash = other.is_a?(Hash) ? other : other.to_h merged_chains = @chains.dup if other_hash.key?(:chains) other_hash[:chains].each { |k, v| merged_chains[k.to_s] = v } end self.class.new( enabled: other_hash.fetch(:enabled, @enabled), retry_count: other_hash.fetch(:retry_count, @retry_count), retry_delay: other_hash.fetch(:retry_delay, @retry_delay), providers: other_hash.fetch(:providers, @providers), chains: merged_chains, max_total_timeout: other_hash.fetch(:max_total_timeout, @max_total_timeout) ) end |
#providers_for(primary) ⇒ Array<String>
Return fallback providers for a specific primary provider Uses per-provider chain if configured, otherwise falls back to default providers
63 64 65 66 |
# File 'lib/ace/llm/models/fallback_config.rb', line 63 def providers_for(primary) key = primary.to_s @chains[key] || @providers end |
#to_h ⇒ Hash
Convert to hash representation
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ace/llm/models/fallback_config.rb', line 70 def to_h { enabled: @enabled, retry_count: @retry_count, retry_delay: @retry_delay, providers: @providers.dup, chains: @chains.transform_values(&:dup), max_total_timeout: @max_total_timeout } end |