Class: LexLLM::Routing::ModelOffering

Inherits:
Object
  • Object
show all
Defined in:
lib/lex_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.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lex_llm/routing/model_offering.rb', line 10

def initialize(data)
  @provider_family = normalize_symbol(fetch_value(data, :provider_family, fetch_value(data, :provider)))
  @instance_id = normalize_symbol(fetch_value(data, :instance_id, @provider_family))
  @transport = normalize_symbol(fetch_value(data, :transport, :http))
  @tier = normalize_symbol(fetch_value(data, :tier, default_tier))
  @model = fetch_value(data, :model).to_s
  @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)
  @metadata = normalize_hash(fetch_value(data, :metadata))
end

Instance Attribute Details

#capabilitiesObject (readonly)

Returns the value of attribute capabilities.



7
8
9
# File 'lib/lex_llm/routing/model_offering.rb', line 7

def capabilities
  @capabilities
end

#costObject (readonly)

Returns the value of attribute cost.



7
8
9
# File 'lib/lex_llm/routing/model_offering.rb', line 7

def cost
  @cost
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



7
8
9
# File 'lib/lex_llm/routing/model_offering.rb', line 7

def credentials
  @credentials
end

#healthObject (readonly)

Returns the value of attribute health.



7
8
9
# File 'lib/lex_llm/routing/model_offering.rb', line 7

def health
  @health
end

#instance_idObject (readonly)

Returns the value of attribute instance_id.



7
8
9
# File 'lib/lex_llm/routing/model_offering.rb', line 7

def instance_id
  @instance_id
end

#limitsObject (readonly)

Returns the value of attribute limits.



7
8
9
# File 'lib/lex_llm/routing/model_offering.rb', line 7

def limits
  @limits
end

#metadataObject (readonly)

Returns the value of attribute metadata.



7
8
9
# File 'lib/lex_llm/routing/model_offering.rb', line 7

def 
  @metadata
end

#modelObject (readonly)

Returns the value of attribute model.



7
8
9
# File 'lib/lex_llm/routing/model_offering.rb', line 7

def model
  @model
end

#policy_tagsObject (readonly)

Returns the value of attribute policy_tags.



7
8
9
# File 'lib/lex_llm/routing/model_offering.rb', line 7

def policy_tags
  @policy_tags
end

#provider_familyObject (readonly)

Returns the value of attribute provider_family.



7
8
9
# File 'lib/lex_llm/routing/model_offering.rb', line 7

def provider_family
  @provider_family
end

#tierObject (readonly)

Returns the value of attribute tier.



7
8
9
# File 'lib/lex_llm/routing/model_offering.rb', line 7

def tier
  @tier
end

#transportObject (readonly)

Returns the value of attribute transport.



7
8
9
# File 'lib/lex_llm/routing/model_offering.rb', line 7

def transport
  @transport
end

#usage_typeObject (readonly)

Returns the value of attribute usage_type.



7
8
9
# File 'lib/lex_llm/routing/model_offering.rb', line 7

def usage_type
  @usage_type
end

Instance Method Details

#context_windowObject



41
42
43
# File 'lib/lex_llm/routing/model_offering.rb', line 41

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

#eligibility_fingerprintObject



67
68
69
# File 'lib/lex_llm/routing/model_offering.rb', line 67

def eligibility_fingerprint
  LaneKey.eligibility_fingerprint(self)
end

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

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
61
# File 'lib/lex_llm/routing/model_offering.rb', line 53

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)


33
34
35
# File 'lib/lex_llm/routing/model_offering.rb', line 33

def embedding?
  usage_type == :embedding
end

#enabled?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/lex_llm/routing/model_offering.rb', line 29

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

#inference?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/lex_llm/routing/model_offering.rb', line 37

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

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



63
64
65
# File 'lib/lex_llm/routing/model_offering.rb', line 63

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

#max_output_tokensObject



45
46
47
# File 'lib/lex_llm/routing/model_offering.rb', line 45

def max_output_tokens
  integer_limit(:max_output_tokens)
end

#supports?(capability) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/lex_llm/routing/model_offering.rb', line 49

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

#to_hObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/lex_llm/routing/model_offering.rb', line 71

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