Class: Legion::LLM::Router::EscalationChain

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Legion::Logging::Helper
Defined in:
lib/legion/llm/router/escalation/chain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resolutions:, max_attempts: 3) ⇒ EscalationChain

Returns a new instance of EscalationChain.



12
13
14
15
16
17
# File 'lib/legion/llm/router/escalation/chain.rb', line 12

def initialize(resolutions:, max_attempts: 3)
  @resolutions = resolutions.dup.freeze
  @max_attempts = max_attempts
  log.debug "[llm][escalation_chain] action=built size=#{@resolutions.size} max_attempts=#{@max_attempts} " \
            "providers=#{@resolutions.map { |r| "#{r.provider}:#{r.model}" }.join(', ')}"
end

Instance Attribute Details

#max_attemptsObject (readonly)

Returns the value of attribute max_attempts.



10
11
12
# File 'lib/legion/llm/router/escalation/chain.rb', line 10

def max_attempts
  @max_attempts
end

Instance Method Details

#eachObject



23
24
25
26
27
# File 'lib/legion/llm/router/escalation/chain.rb', line 23

def each(&)
  return enum_for(:each) unless block_given?

  capped_resolutions.each(&)
end

#empty?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/legion/llm/router/escalation/chain.rb', line 33

def empty?
  @resolutions.empty?
end

#primaryObject



19
20
21
# File 'lib/legion/llm/router/escalation/chain.rb', line 19

def primary
  @resolutions.first
end

#sizeObject



29
30
31
# File 'lib/legion/llm/router/escalation/chain.rb', line 29

def size
  @resolutions.size
end

#to_aObject



37
38
39
# File 'lib/legion/llm/router/escalation/chain.rb', line 37

def to_a
  @resolutions.dup
end