Class: RubyPi::LLM::Fallback
- Inherits:
-
BaseProvider
- Object
- BaseProvider
- RubyPi::LLM::Fallback
- Defined in:
- lib/ruby_pi/llm/fallback.rb
Overview
A resilient provider wrapper that tries a primary provider first and automatically falls back to an alternative provider on failure. Both providers must conform to the BaseProvider interface.
Authentication errors are NOT retried with the fallback since they indicate a configuration problem rather than a transient failure.
Instance Attribute Summary collapse
-
#fallback ⇒ RubyPi::LLM::BaseProvider
readonly
The fallback provider.
-
#primary ⇒ RubyPi::LLM::BaseProvider
readonly
The primary provider.
Attributes inherited from BaseProvider
#max_retries, #retry_base_delay, #retry_max_delay
Instance Method Summary collapse
-
#initialize(primary:, fallback:, **options) ⇒ Fallback
constructor
Creates a new Fallback wrapper with a primary and fallback provider.
-
#model_name ⇒ String
Returns the model name of the primary provider.
-
#provider_name ⇒ Symbol
Returns :fallback as the provider identifier.
Methods inherited from BaseProvider
Constructor Details
#initialize(primary:, fallback:, **options) ⇒ Fallback
Creates a new Fallback wrapper with a primary and fallback provider.
38 39 40 41 42 |
# File 'lib/ruby_pi/llm/fallback.rb', line 38 def initialize(primary:, fallback:, **) super(**) @primary = primary @fallback = fallback end |
Instance Attribute Details
#fallback ⇒ RubyPi::LLM::BaseProvider (readonly)
Returns the fallback provider.
31 32 33 |
# File 'lib/ruby_pi/llm/fallback.rb', line 31 def fallback @fallback end |
#primary ⇒ RubyPi::LLM::BaseProvider (readonly)
Returns the primary provider.
28 29 30 |
# File 'lib/ruby_pi/llm/fallback.rb', line 28 def primary @primary end |
Instance Method Details
#model_name ⇒ String
Returns the model name of the primary provider.
47 48 49 |
# File 'lib/ruby_pi/llm/fallback.rb', line 47 def model_name @primary.model_name end |
#provider_name ⇒ Symbol
Returns :fallback as the provider identifier.
54 55 56 |
# File 'lib/ruby_pi/llm/fallback.rb', line 54 def provider_name :fallback end |