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 =

Returns Engine names that run locally without API calls.

Returns:

  • (Array)

    Engine names that run locally without API calls.

['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



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

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

Instance Attribute Details

#enginesObject (readonly)

Returns the value of attribute engines.



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

def engines
  @engines
end

#warningsObject (readonly)

Returns the value of attribute warnings.



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

def warnings
  @warnings
end

Instance Method Details

#fallbacksArray<String>

Returns fallback engines (all after primary).

Returns:

  • (Array<String>)

    fallback engines (all after primary)



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

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



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

def local_to_remote_transition?
  !@warnings.empty?
end

#primaryString?

Returns primary engine (first in chain).

Returns:

  • (String, nil)

    primary engine (first in chain)



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

def primary
  @engines.first
end

#to_hHash

Returns serializable representation.

Returns:

  • (Hash)

    serializable representation



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

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