Module: RubyLLM::Providers::Bedrock::Capabilities
- Defined in:
- lib/ruby_llm/providers/bedrock/capabilities.rb
Overview
Determines capabilities and pricing for AWS Bedrock models
Constant Summary collapse
- MODEL_FAMILIES =
Model family patterns for capability lookup
{ /anthropic\.claude-3-opus/ => :claude3_opus, /anthropic\.claude-3-sonnet/ => :claude3_sonnet, /anthropic\.claude-3-5-sonnet/ => :claude3_sonnet, /anthropic\.claude-3-7-sonnet/ => :claude3_sonnet, /anthropic\.claude-3-haiku/ => :claude3_haiku, /anthropic\.claude-3-5-haiku/ => :claude3_5_haiku, /anthropic\.claude-v2/ => :claude2, /anthropic\.claude-instant/ => :claude_instant }.freeze
- PRICES =
Pricing information for Bedrock models (per million tokens)
{ claude3_opus: { input: 15.0, output: 75.0 }, claude3_sonnet: { input: 3.0, output: 15.0 }, claude3_haiku: { input: 0.25, output: 1.25 }, claude3_5_haiku: { input: 0.8, output: 4.0 }, claude2: { input: 8.0, output: 24.0 }, claude_instant: { input: 0.8, output: 2.4 } }.freeze
Class Method Summary collapse
- .capabilities_for(model_id) ⇒ Object
- .context_window_for(model_id) ⇒ Object
- .default_input_price ⇒ Object
- .default_output_price ⇒ Object
- .format_display_name(model_id) ⇒ Object
- .humanize(id) ⇒ Object
- .input_price_for(model_id) ⇒ Object
- .max_tokens_for(_model_id) ⇒ Object
- .modalities_for(model_id) ⇒ Object
- .model_family(model_id) ⇒ Object
- .model_type(_model_id) ⇒ Object
- .output_price_for(model_id) ⇒ Object
- .pricing_for(model_id) ⇒ Object
- .supports_audio?(_model_id) ⇒ Boolean
- .supports_chat?(model_id) ⇒ Boolean
- .supports_functions?(model_id) ⇒ Boolean
- .supports_images?(model_id) ⇒ Boolean
- .supports_json_mode?(model_id) ⇒ Boolean
- .supports_streaming?(model_id) ⇒ Boolean
- .supports_structured_output?(_model_id) ⇒ Boolean
- .supports_vision?(model_id) ⇒ Boolean
Class Method Details
.capabilities_for(model_id) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 126 def capabilities_for(model_id) capabilities = [] capabilities << 'streaming' if model_id.match?(/anthropic\.claude/) capabilities << 'function_calling' if supports_functions?(model_id) capabilities << 'reasoning' if model_id.match?(/claude-3-7/) if model_id.match?(/claude-3\.5|claude-3-7/) capabilities << 'batch' capabilities << 'citations' end capabilities end |
.context_window_for(model_id) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 10 def context_window_for(model_id) case model_id when /anthropic\.claude-2/ then 100_000 else 200_000 end end |
.default_input_price ⇒ Object
95 96 97 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 95 def default_input_price 0.1 end |
.default_output_price ⇒ Object
99 100 101 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 99 def default_output_price 0.2 end |
.format_display_name(model_id) ⇒ Object
57 58 59 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 57 def format_display_name(model_id) model_id.then { |id| humanize(id) } end |
.humanize(id) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 103 def humanize(id) id.tr('-', ' ') .split('.') .last .split .map(&:capitalize) .join(' ') end |
.input_price_for(model_id) ⇒ Object
21 22 23 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 21 def input_price_for(model_id) PRICES.dig(model_family(model_id), :input) || default_input_price end |
.max_tokens_for(_model_id) ⇒ Object
17 18 19 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 17 def max_tokens_for(_model_id) 4_096 end |
.modalities_for(model_id) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 112 def modalities_for(model_id) modalities = { input: ['text'], output: ['text'] } if model_id.match?(/anthropic\.claude/) && supports_vision?(model_id) modalities[:input] << 'image' modalities[:input] << 'pdf' end modalities end |
.model_family(model_id) ⇒ Object
81 82 83 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 81 def model_family(model_id) MODEL_FAMILIES.find { |pattern, _family| model_id.match?(pattern) }&.last || :other end |
.model_type(_model_id) ⇒ Object
61 62 63 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 61 def model_type(_model_id) 'chat' end |
.output_price_for(model_id) ⇒ Object
25 26 27 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 25 def output_price_for(model_id) PRICES.dig(model_family(model_id), :output) || default_output_price end |
.pricing_for(model_id) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 143 def pricing_for(model_id) family = model_family(model_id) prices = PRICES.fetch(family, { 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 } { text_tokens: { standard: standard_pricing, batch: batch_pricing } } end |
.supports_audio?(_model_id) ⇒ Boolean
49 50 51 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 49 def supports_audio?(_model_id) false end |
.supports_chat?(model_id) ⇒ Boolean
29 30 31 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 29 def supports_chat?(model_id) model_id.match?(/anthropic\.claude/) end |
.supports_functions?(model_id) ⇒ Boolean
45 46 47 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 45 def supports_functions?(model_id) model_id.match?(/anthropic\.claude/) end |
.supports_images?(model_id) ⇒ Boolean
37 38 39 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 37 def supports_images?(model_id) model_id.match?(/anthropic\.claude/) end |
.supports_json_mode?(model_id) ⇒ Boolean
53 54 55 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 53 def supports_json_mode?(model_id) model_id.match?(/anthropic\.claude/) end |
.supports_streaming?(model_id) ⇒ Boolean
33 34 35 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 33 def supports_streaming?(model_id) model_id.match?(/anthropic\.claude/) end |
.supports_structured_output?(_model_id) ⇒ Boolean
65 66 67 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 65 def supports_structured_output?(_model_id) false end |
.supports_vision?(model_id) ⇒ Boolean
41 42 43 |
# File 'lib/ruby_llm/providers/bedrock/capabilities.rb', line 41 def supports_vision?(model_id) model_id.match?(/anthropic\.claude/) end |