Module: RubyLLM::Providers::Anthropic::Models
- Included in:
- RubyLLM::Providers::Anthropic
- Defined in:
- lib/ruby_llm/providers/anthropic/models.rb
Overview
Models methods of the Anthropic API integration
Class Method Summary collapse
- .extract_cache_creation_tokens(data) ⇒ Object
- .extract_cached_tokens(data) ⇒ Object
- .extract_input_tokens(data) ⇒ Object
- .extract_model_id(data) ⇒ Object
- .extract_output_tokens(data) ⇒ Object
- .models_url ⇒ Object
- .parse_list_models_response(response, slug, _capabilities) ⇒ Object
Class Method Details
.extract_cache_creation_tokens(data) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ruby_llm/providers/anthropic/models.rb', line 44 def extract_cache_creation_tokens(data) direct = data.dig('message', 'usage', 'cache_creation_input_tokens') || data.dig('usage', 'cache_creation_input_tokens') return direct if direct breakdown = data.dig('message', 'usage', 'cache_creation') || data.dig('usage', 'cache_creation') return unless breakdown.is_a?(Hash) breakdown.values.compact.sum end |
.extract_cached_tokens(data) ⇒ Object
40 41 42 |
# File 'lib/ruby_llm/providers/anthropic/models.rb', line 40 def extract_cached_tokens(data) data.dig('message', 'usage', 'cache_read_input_tokens') || data.dig('usage', 'cache_read_input_tokens') end |
.extract_input_tokens(data) ⇒ Object
32 33 34 |
# File 'lib/ruby_llm/providers/anthropic/models.rb', line 32 def extract_input_tokens(data) data.dig('message', 'usage', 'input_tokens') end |
.extract_model_id(data) ⇒ Object
28 29 30 |
# File 'lib/ruby_llm/providers/anthropic/models.rb', line 28 def extract_model_id(data) data.dig('message', 'model') end |
.extract_output_tokens(data) ⇒ Object
36 37 38 |
# File 'lib/ruby_llm/providers/anthropic/models.rb', line 36 def extract_output_tokens(data) data.dig('message', 'usage', 'output_tokens') || data.dig('usage', 'output_tokens') end |
.models_url ⇒ Object
10 11 12 |
# File 'lib/ruby_llm/providers/anthropic/models.rb', line 10 def models_url 'v1/models' end |
.parse_list_models_response(response, slug, _capabilities) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ruby_llm/providers/anthropic/models.rb', line 14 def parse_list_models_response(response, slug, _capabilities) Array(response.body['data']).map do |model_data| model_id = model_data['id'] Model::Info.new( id: model_id, name: model_data['display_name'] || model_id, provider: slug, created_at: Time.parse(model_data['created_at']), metadata: {} ) end end |