Class: LLMs::Models::Model
- Inherits:
-
Object
- Object
- LLMs::Models::Model
- Defined in:
- lib/llms/models/model.rb
Instance Attribute Summary collapse
-
#enabled ⇒ Object
readonly
Returns the value of attribute enabled.
-
#model_name ⇒ Object
readonly
Returns the value of attribute model_name.
-
#pricing ⇒ Object
readonly
Returns the value of attribute pricing.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#supports_thinking ⇒ Object
readonly
Returns the value of attribute supports_thinking.
-
#supports_tools ⇒ Object
readonly
Returns the value of attribute supports_tools.
-
#supports_vision ⇒ Object
readonly
Returns the value of attribute supports_vision.
Instance Method Summary collapse
- #calculate_cost(input_tokens, output_tokens, cache_read_tokens = 0, cache_write_tokens = 0) ⇒ Object
- #certainly_supports_thinking? ⇒ Boolean
- #certainly_supports_tools? ⇒ Boolean
- #certainly_supports_vision? ⇒ Boolean
- #full_name ⇒ Object
-
#initialize(model_name, provider, pricing: nil, supports_tools: nil, supports_vision: nil, supports_thinking: nil, enabled: nil) ⇒ Model
constructor
A new instance of Model.
- #is_enabled? ⇒ Boolean
- #possibly_supports_thinking? ⇒ Boolean
- #possibly_supports_tools? ⇒ Boolean
- #possibly_supports_vision? ⇒ Boolean
Constructor Details
#initialize(model_name, provider, pricing: nil, supports_tools: nil, supports_vision: nil, supports_thinking: nil, enabled: nil) ⇒ Model
Returns a new instance of Model.
6 7 8 9 10 11 12 13 14 |
# File 'lib/llms/models/model.rb', line 6 def initialize(model_name, provider, pricing: nil, supports_tools: nil, supports_vision: nil, supports_thinking: nil, enabled: nil) @model_name = model_name.to_s @provider = provider @pricing = pricing&.transform_keys(&:to_sym) @supports_tools = supports_tools @supports_vision = supports_vision @supports_thinking = supports_thinking @enabled = enabled end |
Instance Attribute Details
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled.
4 5 6 |
# File 'lib/llms/models/model.rb', line 4 def enabled @enabled end |
#model_name ⇒ Object (readonly)
Returns the value of attribute model_name.
4 5 6 |
# File 'lib/llms/models/model.rb', line 4 def model_name @model_name end |
#pricing ⇒ Object (readonly)
Returns the value of attribute pricing.
4 5 6 |
# File 'lib/llms/models/model.rb', line 4 def pricing @pricing end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
4 5 6 |
# File 'lib/llms/models/model.rb', line 4 def provider @provider end |
#supports_thinking ⇒ Object (readonly)
Returns the value of attribute supports_thinking.
4 5 6 |
# File 'lib/llms/models/model.rb', line 4 def supports_thinking @supports_thinking end |
#supports_tools ⇒ Object (readonly)
Returns the value of attribute supports_tools.
4 5 6 |
# File 'lib/llms/models/model.rb', line 4 def supports_tools @supports_tools end |
#supports_vision ⇒ Object (readonly)
Returns the value of attribute supports_vision.
4 5 6 |
# File 'lib/llms/models/model.rb', line 4 def supports_vision @supports_vision end |
Instance Method Details
#calculate_cost(input_tokens, output_tokens, cache_read_tokens = 0, cache_write_tokens = 0) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/llms/models/model.rb', line 60 def calculate_cost(input_tokens, output_tokens, cache_read_tokens = 0, cache_write_tokens = 0) return 0.0 if @pricing.empty? cost = 0.0 if input_tokens && input_tokens > 0 && @pricing[:input] cost += (input_tokens / 1_000_000.0) * @pricing[:input] end if output_tokens && output_tokens > 0 && @pricing[:output] cost += (output_tokens / 1_000_000.0) * @pricing[:output] end if cache_read_tokens && cache_read_tokens > 0 && @pricing[:cache_read] cost += (cache_read_tokens / 1_000_000.0) * @pricing[:cache_read] end if cache_write_tokens && cache_write_tokens > 0 && @pricing[:cache_write] cost += (cache_write_tokens / 1_000_000.0) * @pricing[:cache_write] end cost end |
#certainly_supports_thinking? ⇒ Boolean
48 49 50 51 52 53 54 |
# File 'lib/llms/models/model.rb', line 48 def certainly_supports_thinking? ( @provider.certainly_supports_thinking? && (@supports_thinking != false) ) || ( @provider.possibly_supports_thinking? && (@supports_thinking == true) ) end |
#certainly_supports_tools? ⇒ Boolean
24 25 26 27 28 29 30 |
# File 'lib/llms/models/model.rb', line 24 def certainly_supports_tools? ( @provider.certainly_supports_tools? && (@supports_tools != false) ) || ( @provider.possibly_supports_tools? && (@supports_tools == true) ) end |
#certainly_supports_vision? ⇒ Boolean
36 37 38 39 40 41 42 |
# File 'lib/llms/models/model.rb', line 36 def certainly_supports_vision? ( @provider.certainly_supports_vision? && (@supports_vision != false) ) || ( @provider.possibly_supports_vision? && (@supports_vision == true) ) end |
#full_name ⇒ Object
16 17 18 |
# File 'lib/llms/models/model.rb', line 16 def full_name "#{@provider.provider_name}:#{@model_name}" end |
#is_enabled? ⇒ Boolean
56 57 58 |
# File 'lib/llms/models/model.rb', line 56 def is_enabled? @provider.is_enabled? && (@enabled != false) end |
#possibly_supports_thinking? ⇒ Boolean
44 45 46 |
# File 'lib/llms/models/model.rb', line 44 def possibly_supports_thinking? @provider.possibly_supports_thinking? && (@supports_thinking != false) end |
#possibly_supports_tools? ⇒ Boolean
20 21 22 |
# File 'lib/llms/models/model.rb', line 20 def possibly_supports_tools? @provider.possibly_supports_tools? && (@supports_tools != false) end |
#possibly_supports_vision? ⇒ Boolean
32 33 34 |
# File 'lib/llms/models/model.rb', line 32 def possibly_supports_vision? @provider.possibly_supports_vision? && (@supports_vision != false) end |