Module: RubyLLM::Providers::Anthropic::Capabilities

Defined in:
lib/ruby_llm/providers/anthropic/capabilities.rb

Overview

Determines capabilities and pricing for Anthropic models

Constant Summary collapse

PRICES =
{
  'claude-3-7-sonnet': { input: 3.0, output: 15.0 },
  'claude-3-5-sonnet': { input: 3.0, output: 15.0 },
  'claude-3-5-haiku': { input: 0.80, output: 4.0 },
  'claude-3-opus': { input: 15.0, output: 75.0 },
  'claude-3-haiku': { input: 0.25, output: 1.25 },
  'claude-2': { input: 3.0, output: 15.0 }
}.freeze

Class Method Summary collapse

Class Method Details

.capabilities_for(model_id) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/ruby_llm/providers/anthropic/capabilities.rb', line 92

def capabilities_for(model_id)
  capabilities = ['streaming']

  if model_id.match?(/claude-3/)
    capabilities << 'function_calling'
    capabilities << 'batch'
  end

  capabilities << 'reasoning' if model_id.match?(/claude-3-7|-4/)
  capabilities << 'citations' if model_id.match?(/claude-3\.5|claude-3-7/)
  capabilities
end

.default_input_priceObject



70
71
72
# File 'lib/ruby_llm/providers/anthropic/capabilities.rb', line 70

def default_input_price
  3.0
end

.default_output_priceObject



74
75
76
# File 'lib/ruby_llm/providers/anthropic/capabilities.rb', line 74

def default_output_price
  15.0
end

.determine_context_window(_model_id) ⇒ Object



10
11
12
# File 'lib/ruby_llm/providers/anthropic/capabilities.rb', line 10

def determine_context_window(_model_id)
  200_000
end

.determine_max_tokens(model_id) ⇒ Object



14
15
16
17
18
19
# File 'lib/ruby_llm/providers/anthropic/capabilities.rb', line 14

def determine_max_tokens(model_id)
  case model_id
  when /claude-3-7-sonnet/, /claude-3-5/ then 8_192
  else 4_096
  end
end

.get_input_price(model_id) ⇒ Object



21
22
23
# File 'lib/ruby_llm/providers/anthropic/capabilities.rb', line 21

def get_input_price(model_id)
  PRICES.dig(model_family(model_id), :input) || default_input_price
end

.get_output_price(model_id) ⇒ Object



25
26
27
# File 'lib/ruby_llm/providers/anthropic/capabilities.rb', line 25

def get_output_price(model_id)
  PRICES.dig(model_family(model_id), :output) || default_output_price
end

.modalities_for(model_id) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ruby_llm/providers/anthropic/capabilities.rb', line 78

def modalities_for(model_id)
  modalities = {
    input: ['text'],
    output: ['text']
  }

  unless model_id.match?(/claude-[12]/)
    modalities[:input] << 'image'
    modalities[:input] << 'pdf'
  end

  modalities
end

.model_family(model_id) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ruby_llm/providers/anthropic/capabilities.rb', line 45

def model_family(model_id)
  case model_id
  when /claude-3-7-sonnet/  then 'claude-3-7-sonnet'
  when /claude-3-5-sonnet/  then 'claude-3-5-sonnet'
  when /claude-3-5-haiku/   then 'claude-3-5-haiku'
  when /claude-3-opus/      then 'claude-3-opus'
  when /claude-3-sonnet/    then 'claude-3-sonnet'
  when /claude-3-haiku/     then 'claude-3-haiku'
  else 'claude-2'
  end
end

.model_type(_) ⇒ Object



57
58
59
# File 'lib/ruby_llm/providers/anthropic/capabilities.rb', line 57

def model_type(_)
  'chat'
end

.pricing_for(model_id) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/ruby_llm/providers/anthropic/capabilities.rb', line 105

def pricing_for(model_id)
  family = model_family(model_id)
  prices = PRICES.fetch(family.to_sym, { input: default_input_price, output: default_output_price })

  standard_pricing = {
    input_per_million: prices[:input],
    output_per_million: prices[:output]
  }

  batch_pricing = {
    input_per_million: prices[:input] * 0.5,
    output_per_million: prices[:output] * 0.5
  }

  if model_id.match?(/claude-3-7/)
    standard_pricing[:reasoning_output_per_million] = prices[:output] * 2.5
    batch_pricing[:reasoning_output_per_million] = prices[:output] * 1.25
  end

  {
    text_tokens: {
      standard: standard_pricing,
      batch: batch_pricing
    }
  }
end

.supports_extended_thinking?(model_id) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/ruby_llm/providers/anthropic/capabilities.rb', line 41

def supports_extended_thinking?(model_id)
  model_id.match?(/claude-3-7-sonnet/)
end

.supports_functions?(model_id) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/ruby_llm/providers/anthropic/capabilities.rb', line 33

def supports_functions?(model_id)
  model_id.match?(/claude-3/)
end

.supports_json_mode?(model_id) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/ruby_llm/providers/anthropic/capabilities.rb', line 37

def supports_json_mode?(model_id)
  model_id.match?(/claude-3/)
end

.supports_vision?(model_id) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/ruby_llm/providers/anthropic/capabilities.rb', line 29

def supports_vision?(model_id)
  !model_id.match?(/claude-[12]/)
end