Class: Legion::Extensions::Llm::Routing::ModelOffering

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

Overview

Describes one concrete model made available by one provider instance.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ModelOffering

Returns a new instance of ModelOffering.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 13

def initialize(data)
  @metadata = normalize_hash(fetch_value(data, :metadata))
  @provider_family = normalize_symbol(fetch_value(data, :provider_family, fetch_value(data, :provider)))
  @model_family = normalize_symbol(fetch_value(data, :model_family, @metadata[:model_family]))
  @provider_instance = normalize_symbol(fetch_value(data, :provider_instance,
                                                    fetch_value(data, :instance_id, @provider_family)))
  @instance_id = @provider_instance
  @transport = normalize_symbol(fetch_value(data, :transport, :http))
  @tier = normalize_symbol(fetch_value(data, :tier, default_tier))
  @model = fetch_value(data, :model).to_s
  @canonical_model_alias = normalize_model_alias(fetch_value(data, :canonical_model_alias,
                                                             ))
  @routing_metadata = normalize_hash(fetch_value(data, :routing_metadata))
  @usage_type = normalize_usage_type(fetch_value(data, :usage_type,
                                                 fetch_value(data, :type) ||
                                                 fetch_value(data, :kind) ||
                                                 infer_usage_type(data)))
  @capabilities = normalize_array(fetch_value(data, :capabilities))
  @limits = normalize_hash(fetch_value(data, :limits))
  @credentials = fetch_value(data, :credentials)
  @health = normalize_hash(fetch_value(data, :health))
  @cost = normalize_hash(fetch_value(data, :cost))
  @policy_tags = normalize_array(fetch_value(data, :policy_tags)).map(&:to_sym)
  @offering_id = normalize_offering_id(fetch_value(data, :offering_id, default_offering_id))
end

Instance Attribute Details

#canonical_model_aliasObject (readonly)

Returns the value of attribute canonical_model_alias.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def canonical_model_alias
  @canonical_model_alias
end

#capabilitiesObject (readonly)

Returns the value of attribute capabilities.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def capabilities
  @capabilities
end

#costObject (readonly)

Returns the value of attribute cost.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def cost
  @cost
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def credentials
  @credentials
end

#healthObject (readonly)

Returns the value of attribute health.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def health
  @health
end

#instance_idObject (readonly)

Returns the value of attribute instance_id.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def instance_id
  @instance_id
end

#limitsObject (readonly)

Returns the value of attribute limits.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def limits
  @limits
end

#metadataObject (readonly)

Returns the value of attribute metadata.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def 
  @metadata
end

#modelObject (readonly)

Returns the value of attribute model.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def model
  @model
end

#model_familyObject (readonly)

Returns the value of attribute model_family.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def model_family
  @model_family
end

#offering_idObject (readonly)

Returns the value of attribute offering_id.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def offering_id
  @offering_id
end

#policy_tagsObject (readonly)

Returns the value of attribute policy_tags.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def policy_tags
  @policy_tags
end

#provider_familyObject (readonly)

Returns the value of attribute provider_family.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def provider_family
  @provider_family
end

#provider_instanceObject (readonly)

Returns the value of attribute provider_instance.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def provider_instance
  @provider_instance
end

#routing_metadataObject (readonly)

Returns the value of attribute routing_metadata.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def 
  @routing_metadata
end

#tierObject (readonly)

Returns the value of attribute tier.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def tier
  @tier
end

#transportObject (readonly)

Returns the value of attribute transport.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def transport
  @transport
end

#usage_typeObject (readonly)

Returns the value of attribute usage_type.



9
10
11
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9

def usage_type
  @usage_type
end

Instance Method Details

#context_windowObject



51
52
53
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 51

def context_window
  integer_limit(:context_window) || integer_limit(:max_input_tokens)
end

#eligibility_fingerprintObject



77
78
79
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 77

def eligibility_fingerprint
  LaneKey.eligibility_fingerprint(self)
end

#eligible_for?(usage_type: nil, required_capabilities: [], min_context_window: nil, policy_tags: []) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
71
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 63

def eligible_for?(usage_type: nil, required_capabilities: [], min_context_window: nil, policy_tags: [])
  return false unless enabled?
  return false unless usage_type_matches?(usage_type)
  return false unless capabilities_match?(required_capabilities)
  return false unless context_window_matches?(min_context_window)
  return false unless policy_tags_match?(policy_tags)

  true
end

#embedding?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 43

def embedding?
  usage_type == :embedding
end

#enabled?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 39

def enabled?
  !.key?(:enabled) || [:enabled] != false
end

#inference?Boolean

Returns:

  • (Boolean)


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

def inference?
  %i[chat inference completion].include?(usage_type)
end

#lane_key(prefix: 'llm.fleet', include_context: true, include_fingerprint: false) ⇒ Object



73
74
75
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 73

def lane_key(prefix: 'llm.fleet', include_context: true, include_fingerprint: false)
  LaneKey.for(self, prefix:, include_context:, include_fingerprint:)
end

#max_output_tokensObject



55
56
57
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 55

def max_output_tokens
  integer_limit(:max_output_tokens)
end

#model_alias?(alias_name) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
84
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 81

def model_alias?(alias_name)
  normalized = normalize_model_alias(alias_name)
  [canonical_model_alias, model].compact.any? { |candidate| normalize_model_alias(candidate) == normalized }
end

#supports?(capability) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 59

def supports?(capability)
  capabilities.include?(capability.to_sym)
end

#to_hObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 86

def to_h
  {
    offering_id: offering_id,
    provider_family: provider_family,
    model_family: model_family,
    provider_instance: provider_instance,
    instance_id: instance_id,
    transport: transport,
    tier: tier,
    model: model,
    canonical_model_alias: canonical_model_alias,
    routing_metadata: ,
    usage_type: usage_type,
    capabilities: capabilities,
    limits: limits,
    credentials: credentials,
    health: health,
    cost: cost,
    policy_tags: policy_tags,
    metadata: 
  }
end