Class: Legion::Extensions::Llm::Routing::ModelOffering
- Inherits:
-
Object
- Object
- Legion::Extensions::Llm::Routing::ModelOffering
- 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
-
#canonical_model_alias ⇒ Object
readonly
Returns the value of attribute canonical_model_alias.
-
#capabilities ⇒ Object
readonly
Returns the value of attribute capabilities.
-
#cost ⇒ Object
readonly
Returns the value of attribute cost.
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#health ⇒ Object
readonly
Returns the value of attribute health.
-
#instance_id ⇒ Object
readonly
Returns the value of attribute instance_id.
-
#limits ⇒ Object
readonly
Returns the value of attribute limits.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#model_family ⇒ Object
readonly
Returns the value of attribute model_family.
-
#offering_id ⇒ Object
readonly
Returns the value of attribute offering_id.
-
#policy_tags ⇒ Object
readonly
Returns the value of attribute policy_tags.
-
#provider_family ⇒ Object
readonly
Returns the value of attribute provider_family.
-
#provider_instance ⇒ Object
readonly
Returns the value of attribute provider_instance.
-
#routing_metadata ⇒ Object
readonly
Returns the value of attribute routing_metadata.
-
#tier ⇒ Object
readonly
Returns the value of attribute tier.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
-
#usage_type ⇒ Object
readonly
Returns the value of attribute usage_type.
Instance Method Summary collapse
- #context_window ⇒ Object
- #eligibility_fingerprint ⇒ Object
- #eligible_for?(usage_type: nil, required_capabilities: [], min_context_window: nil, policy_tags: []) ⇒ Boolean
- #embedding? ⇒ Boolean
- #enabled? ⇒ Boolean
- #inference? ⇒ Boolean
-
#initialize(data) ⇒ ModelOffering
constructor
A new instance of ModelOffering.
- #lane_key(prefix: 'llm.fleet', include_context: true, include_fingerprint: false) ⇒ Object
- #max_output_tokens ⇒ Object
- #model_alias?(alias_name) ⇒ Boolean
- #supports?(capability) ⇒ Boolean
- #to_h ⇒ Object
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_alias ⇒ Object (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 |
#capabilities ⇒ Object (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 |
#cost ⇒ Object (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 |
#credentials ⇒ Object (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 |
#health ⇒ Object (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_id ⇒ Object (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 |
#limits ⇒ Object (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 |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 9 def @metadata end |
#model ⇒ Object (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_family ⇒ Object (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_id ⇒ Object (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_tags ⇒ Object (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 end |
#provider_family ⇒ Object (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_instance ⇒ Object (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_metadata ⇒ Object (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 |
#tier ⇒ Object (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 |
#transport ⇒ Object (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_type ⇒ Object (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_window ⇒ Object
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_fingerprint ⇒ Object
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
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 () true end |
#embedding? ⇒ Boolean
43 44 45 |
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 43 def usage_type == :embedding end |
#enabled? ⇒ Boolean
39 40 41 |
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 39 def enabled? !.key?(:enabled) || [:enabled] != false end |
#inference? ⇒ 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_tokens ⇒ Object
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
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
59 60 61 |
# File 'lib/legion/extensions/llm/routing/model_offering.rb', line 59 def supports?(capability) capabilities.include?(capability.to_sym) end |
#to_h ⇒ Object
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: , metadata: } end |