Class: RosettAi::AiConfig::FallbackChain

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/ai_config/fallback_chain.rb

Overview

Ordered engine fallback chain with local-to-remote transition warnings.

When the primary engine is unavailable, the chain specifies fallback engines in order. Warns when a fallback would switch from local to remote (network requirement change).

Constant Summary collapse

LOCAL_ENGINES =
['ollama', 'gpt_neox'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(engines: []) ⇒ FallbackChain

Returns a new instance of FallbackChain.

Parameters:

  • engines (Array<String>) (defaults to: [])

    ordered engine identifiers



19
20
21
22
# File 'lib/rosett_ai/ai_config/fallback_chain.rb', line 19

def initialize(engines: [])
  @engines = engines.freeze
  @warnings = detect_transition_warnings.freeze
end

Instance Attribute Details

#enginesObject (readonly)

Returns the value of attribute engines.



16
17
18
# File 'lib/rosett_ai/ai_config/fallback_chain.rb', line 16

def engines
  @engines
end

#warningsObject (readonly)

Returns the value of attribute warnings.



16
17
18
# File 'lib/rosett_ai/ai_config/fallback_chain.rb', line 16

def warnings
  @warnings
end

Instance Method Details

#fallbacksArray<String>

Returns fallback engines (all after primary).

Returns:

  • (Array<String>)

    fallback engines (all after primary)



30
31
32
# File 'lib/rosett_ai/ai_config/fallback_chain.rb', line 30

def fallbacks
  @engines.drop(1)
end

#local_to_remote_transition?Boolean

Returns true if chain contains local-to-remote transitions.

Returns:

  • (Boolean)

    true if chain contains local-to-remote transitions



35
36
37
# File 'lib/rosett_ai/ai_config/fallback_chain.rb', line 35

def local_to_remote_transition?
  !@warnings.empty?
end

#primaryString?

Returns primary engine (first in chain).

Returns:

  • (String, nil)

    primary engine (first in chain)



25
26
27
# File 'lib/rosett_ai/ai_config/fallback_chain.rb', line 25

def primary
  @engines.first
end

#to_hHash

Returns serializable representation.

Returns:

  • (Hash)

    serializable representation



40
41
42
43
44
45
# File 'lib/rosett_ai/ai_config/fallback_chain.rb', line 40

def to_h
  {
    'engines' => @engines.dup,
    'warnings' => @warnings.dup
  }
end