Class: RubyLLM::Model::Info

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/model/info.rb

Overview

Information about an AI model’s capabilities, pricing, and metadata.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Info

Returns a new instance of Info.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby_llm/model/info.rb', line 22

def initialize(data)
  @id = data[:id]
  @name = data[:name]
  @provider = data[:provider]
  @family = data[:family]
  @created_at = Utils.to_time(data[:created_at])
  @context_window = data[:context_window]
  @max_output_tokens = data[:max_output_tokens]
  @knowledge_cutoff = Utils.to_date(data[:knowledge_cutoff])
  @modalities = Modalities.new(data[:modalities] || {})
  @capabilities = data[:capabilities] || []
  @pricing = Pricing.new(data[:pricing] || {})
   = data[:metadata] || {}
end

Instance Attribute Details

#capabilitiesObject (readonly)

Returns the value of attribute capabilities.



7
8
9
# File 'lib/ruby_llm/model/info.rb', line 7

def capabilities
  @capabilities
end

#context_windowObject (readonly)

Returns the value of attribute context_window.



7
8
9
# File 'lib/ruby_llm/model/info.rb', line 7

def context_window
  @context_window
end

#created_atObject (readonly)

Returns the value of attribute created_at.



7
8
9
# File 'lib/ruby_llm/model/info.rb', line 7

def created_at
  @created_at
end

#familyObject (readonly)

Returns the value of attribute family.



7
8
9
# File 'lib/ruby_llm/model/info.rb', line 7

def family
  @family
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/ruby_llm/model/info.rb', line 7

def id
  @id
end

#knowledge_cutoffObject (readonly)

Returns the value of attribute knowledge_cutoff.



7
8
9
# File 'lib/ruby_llm/model/info.rb', line 7

def knowledge_cutoff
  @knowledge_cutoff
end

#max_output_tokensObject (readonly)

Returns the value of attribute max_output_tokens.



7
8
9
# File 'lib/ruby_llm/model/info.rb', line 7

def max_output_tokens
  @max_output_tokens
end

#metadataObject (readonly)

Returns the value of attribute metadata.



7
8
9
# File 'lib/ruby_llm/model/info.rb', line 7

def 
  
end

#modalitiesObject (readonly)

Returns the value of attribute modalities.



7
8
9
# File 'lib/ruby_llm/model/info.rb', line 7

def modalities
  @modalities
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/ruby_llm/model/info.rb', line 7

def name
  @name
end

#pricingObject (readonly)

Returns the value of attribute pricing.



7
8
9
# File 'lib/ruby_llm/model/info.rb', line 7

def pricing
  @pricing
end

#providerObject (readonly)

Returns the value of attribute provider.



7
8
9
# File 'lib/ruby_llm/model/info.rb', line 7

def provider
  @provider
end

Class Method Details

.default(model_id, provider) ⇒ Object

Create a default model with assumed capabilities



11
12
13
14
15
16
17
18
19
20
# File 'lib/ruby_llm/model/info.rb', line 11

def self.default(model_id, provider)
  new(
    id: model_id,
    name: model_id.tr('-', ' ').capitalize,
    provider: provider,
    capabilities: %w[function_calling streaming vision structured_output],
    modalities: { input: %w[text image], output: %w[text] },
    metadata: { warning: 'Assuming model exists, capabilities may not be accurate' }
  )
end

Instance Method Details

#display_nameObject



47
48
49
# File 'lib/ruby_llm/model/info.rb', line 47

def display_name
  name
end

#input_price_per_millionObject



67
68
69
# File 'lib/ruby_llm/model/info.rb', line 67

def input_price_per_million
  pricing.text_tokens.input
end

#max_tokensObject



51
52
53
# File 'lib/ruby_llm/model/info.rb', line 51

def max_tokens
  max_output_tokens
end

#output_price_per_millionObject



71
72
73
# File 'lib/ruby_llm/model/info.rb', line 71

def output_price_per_million
  pricing.text_tokens.output
end

#provider_classObject



75
76
77
# File 'lib/ruby_llm/model/info.rb', line 75

def provider_class
  RubyLLM::Provider.resolve provider
end

#supports?(capability) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/ruby_llm/model/info.rb', line 37

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

#supports_functions?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/ruby_llm/model/info.rb', line 63

def supports_functions?
  function_calling?
end

#supports_video?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/ruby_llm/model/info.rb', line 59

def supports_video?
  modalities.input.include?('video')
end

#supports_vision?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/ruby_llm/model/info.rb', line 55

def supports_vision?
  modalities.input.include?('image')
end

#to_hObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/ruby_llm/model/info.rb', line 93

def to_h
  {
    id: id,
    name: name,
    provider: provider,
    family: family,
    created_at: created_at,
    context_window: context_window,
    max_output_tokens: max_output_tokens,
    knowledge_cutoff: knowledge_cutoff,
    modalities: modalities.to_h,
    capabilities: capabilities,
    pricing: pricing.to_h,
    metadata: 
  }
end

#typeObject

rubocop:disable Metrics/PerceivedComplexity



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ruby_llm/model/info.rb', line 79

def type # rubocop:disable Metrics/PerceivedComplexity
  if modalities.output.include?('embeddings') && !modalities.output.include?('text')
    'embedding'
  elsif modalities.output.include?('image') && !modalities.output.include?('text')
    'image'
  elsif modalities.output.include?('audio') && !modalities.output.include?('text')
    'audio'
  elsif modalities.output.include?('moderation')
    'moderation'
  else
    'chat'
  end
end