Class: Legion::Extensions::Llm::Routing::Exclusion

Inherits:
Data
  • Object
show all
Defined in:
lib/legion/extensions/llm/routing/records.rb

Overview

A request-local or attempt-group exclusion of a typed target. See 15.3.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_kind:, target:, reason:, evidence:, lifetime:) ⇒ Exclusion

Returns a new instance of Exclusion.



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/legion/extensions/llm/routing/records.rb', line 48

def initialize(target_kind:, target:, reason:, evidence:, lifetime:)
  raise Legion::Extensions::Llm::Inventory::Errors::ValidationError, 'invalid target_kind' unless Legion::Extensions::Llm::Taxonomies::EXCLUSION_TARGET_KINDS.include?(target_kind)
  raise Legion::Extensions::Llm::Inventory::Errors::ValidationError, 'invalid lifetime' unless Legion::Extensions::Llm::Taxonomies::EXCLUSION_LIFETIMES.include?(lifetime)

  super(
    target_kind: target_kind,
    target: normalize_target(target_kind, target),
    reason: Legion::Extensions::Llm::Inventory::RecordSupport.sanitized_reason(value: reason, field: :reason),
    evidence: Legion::Extensions::Llm::Inventory::ImmutableValue.copy_and_freeze(value: evidence, field: :evidence),
    lifetime: lifetime
  )
end

Instance Attribute Details

#evidenceObject (readonly)

Returns the value of attribute evidence

Returns:

  • (Object)

    the current value of evidence



47
48
49
# File 'lib/legion/extensions/llm/routing/records.rb', line 47

def evidence
  @evidence
end

#lifetimeObject (readonly)

Returns the value of attribute lifetime

Returns:

  • (Object)

    the current value of lifetime



47
48
49
# File 'lib/legion/extensions/llm/routing/records.rb', line 47

def lifetime
  @lifetime
end

#reasonObject (readonly)

Returns the value of attribute reason

Returns:

  • (Object)

    the current value of reason



47
48
49
# File 'lib/legion/extensions/llm/routing/records.rb', line 47

def reason
  @reason
end

#targetObject (readonly)

Returns the value of attribute target

Returns:

  • (Object)

    the current value of target



47
48
49
# File 'lib/legion/extensions/llm/routing/records.rb', line 47

def target
  @target
end

#target_kindObject (readonly)

Returns the value of attribute target_kind

Returns:

  • (Object)

    the current value of target_kind



47
48
49
# File 'lib/legion/extensions/llm/routing/records.rb', line 47

def target_kind
  @target_kind
end

Instance Method Details

#normalize_target(target_kind, target) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/legion/extensions/llm/routing/records.rb', line 61

def normalize_target(target_kind, target)
  errors = Legion::Extensions::Llm::Inventory::Errors
  case target_kind
  when :attempt_target
    raise errors::ValidationError, 'attempt_target target must be an AttemptTargetKey' unless target.is_a?(AttemptTargetKey)

    target
  when :instance
    raise errors::ValidationError, 'instance target must be an InstanceKey' unless target.is_a?(Legion::Extensions::Llm::Inventory::Identity::InstanceKey)

    target
  when :quota_domain
    raise errors::ValidationError, 'quota_domain target must be a QuotaDomainKey' unless target.is_a?(QuotaDomainKey)

    target
  when :provider
    Legion::Extensions::Llm::Inventory::RecordSupport.normalize_provider_family(value: target, field: :target)
  else # :lane, :offering, :model
    Legion::Extensions::Llm::Inventory::Identity.normalize_text(value: target, field: target_kind)
  end
end