Class: RubyLLM::Model::Info
- Inherits:
-
Object
- Object
- RubyLLM::Model::Info
- Defined in:
- lib/ruby_llm/model/info.rb
Overview
Information about an AI model’s capabilities, pricing, and metadata.
Instance Attribute Summary collapse
-
#capabilities ⇒ Object
readonly
Returns the value of attribute capabilities.
-
#context_window ⇒ Object
readonly
Returns the value of attribute context_window.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#family ⇒ Object
readonly
Returns the value of attribute family.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#knowledge_cutoff ⇒ Object
readonly
Returns the value of attribute knowledge_cutoff.
-
#max_output_tokens ⇒ Object
readonly
Returns the value of attribute max_output_tokens.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#modalities ⇒ Object
readonly
Returns the value of attribute modalities.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pricing ⇒ Object
readonly
Returns the value of attribute pricing.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Class Method Summary collapse
-
.default(model_id, provider) ⇒ Object
Create a default model with assumed capabilities.
Instance Method Summary collapse
- #display_name ⇒ Object
-
#initialize(data) ⇒ Info
constructor
A new instance of Info.
- #input_price_per_million ⇒ Object
- #max_tokens ⇒ Object
- #output_price_per_million ⇒ Object
- #provider_class ⇒ Object
- #supports?(capability) ⇒ Boolean
- #supports_functions? ⇒ Boolean
- #supports_video? ⇒ Boolean
- #supports_vision? ⇒ Boolean
- #to_h ⇒ Object
-
#type ⇒ Object
rubocop:disable Metrics/PerceivedComplexity.
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
#capabilities ⇒ Object (readonly)
Returns the value of attribute capabilities.
7 8 9 |
# File 'lib/ruby_llm/model/info.rb', line 7 def capabilities @capabilities end |
#context_window ⇒ Object (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_at ⇒ Object (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 |
#family ⇒ Object (readonly)
Returns the value of attribute family.
7 8 9 |
# File 'lib/ruby_llm/model/info.rb', line 7 def family @family end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/ruby_llm/model/info.rb', line 7 def id @id end |
#knowledge_cutoff ⇒ Object (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_tokens ⇒ Object (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 |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/ruby_llm/model/info.rb', line 7 def end |
#modalities ⇒ Object (readonly)
Returns the value of attribute modalities.
7 8 9 |
# File 'lib/ruby_llm/model/info.rb', line 7 def modalities @modalities end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/ruby_llm/model/info.rb', line 7 def name @name end |
#pricing ⇒ Object (readonly)
Returns the value of attribute pricing.
7 8 9 |
# File 'lib/ruby_llm/model/info.rb', line 7 def pricing @pricing end |
#provider ⇒ Object (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_name ⇒ Object
47 48 49 |
# File 'lib/ruby_llm/model/info.rb', line 47 def display_name name end |
#input_price_per_million ⇒ Object
67 68 69 |
# File 'lib/ruby_llm/model/info.rb', line 67 def input_price_per_million pricing.text_tokens.input end |
#max_tokens ⇒ Object
51 52 53 |
# File 'lib/ruby_llm/model/info.rb', line 51 def max_tokens max_output_tokens end |
#output_price_per_million ⇒ Object
71 72 73 |
# File 'lib/ruby_llm/model/info.rb', line 71 def output_price_per_million pricing.text_tokens.output end |
#provider_class ⇒ Object
75 76 77 |
# File 'lib/ruby_llm/model/info.rb', line 75 def provider_class RubyLLM::Provider.resolve provider end |
#supports?(capability) ⇒ 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
63 64 65 |
# File 'lib/ruby_llm/model/info.rb', line 63 def supports_functions? function_calling? end |
#supports_video? ⇒ Boolean
59 60 61 |
# File 'lib/ruby_llm/model/info.rb', line 59 def supports_video? modalities.input.include?('video') end |
#supports_vision? ⇒ Boolean
55 56 57 |
# File 'lib/ruby_llm/model/info.rb', line 55 def supports_vision? modalities.input.include?('image') end |
#to_h ⇒ Object
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 |
#type ⇒ Object
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 |