Module: RubyLLM::Providers::Perplexity::Capabilities
- Defined in:
- lib/ruby_llm/providers/perplexity/capabilities.rb
Overview
Determines capabilities and pricing for Perplexity models
Constant Summary collapse
- PRICES =
{ sonar: { input: 1.0, output: 1.0 }, sonar_pro: { input: 3.0, output: 15.0 }, sonar_reasoning: { input: 1.0, output: 5.0 }, sonar_reasoning_pro: { input: 2.0, output: 8.0 }, sonar_deep_research: { input: 2.0, output: 8.0, citation: 2.0, reasoning: 3.0, search_queries: 5.0 } }.freeze
Class Method Summary collapse
- .capabilities_for(model_id) ⇒ Object
- .context_window_for(model_id) ⇒ Object
- .format_display_name(model_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_functions?(_model_id) ⇒ Boolean
- .supports_json_mode?(_model_id) ⇒ Boolean
- .supports_vision?(model_id) ⇒ Boolean
Class Method Details
.capabilities_for(model_id) ⇒ Object
83 84 85 86 87 |
# File 'lib/ruby_llm/providers/perplexity/capabilities.rb', line 83 def capabilities_for(model_id) capabilities = %w[streaming json_mode] capabilities << 'vision' if supports_vision?(model_id) capabilities end |
.context_window_for(model_id) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/ruby_llm/providers/perplexity/capabilities.rb', line 10 def context_window_for(model_id) case model_id when /sonar-pro/ then 200_000 else 128_000 end end |
.format_display_name(model_id) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ruby_llm/providers/perplexity/capabilities.rb', line 47 def format_display_name(model_id) case model_id when 'sonar' then 'Sonar' when 'sonar-pro' then 'Sonar Pro' when 'sonar-reasoning' then 'Sonar Reasoning' when 'sonar-reasoning-pro' then 'Sonar Reasoning Pro' when 'sonar-deep-research' then 'Sonar Deep Research' else model_id.split('-') .map(&:capitalize) .join(' ') end end |
.input_price_for(model_id) ⇒ Object
24 25 26 |
# File 'lib/ruby_llm/providers/perplexity/capabilities.rb', line 24 def input_price_for(model_id) PRICES.dig(model_family(model_id), :input) || 1.0 end |
.max_tokens_for(model_id) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/ruby_llm/providers/perplexity/capabilities.rb', line 17 def max_tokens_for(model_id) case model_id when /sonar-(?:pro|reasoning-pro)/ then 8_192 else 4_096 end end |
.modalities_for(_model_id) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/ruby_llm/providers/perplexity/capabilities.rb', line 76 def modalities_for(_model_id) { input: ['text'], output: ['text'] } end |
.model_family(model_id) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ruby_llm/providers/perplexity/capabilities.rb', line 65 def model_family(model_id) case model_id when 'sonar' then :sonar when 'sonar-pro' then :sonar_pro when 'sonar-reasoning' then :sonar_reasoning when 'sonar-reasoning-pro' then :sonar_reasoning_pro when 'sonar-deep-research' then :sonar_deep_research else :unknown end end |
.model_type(_model_id) ⇒ Object
61 62 63 |
# File 'lib/ruby_llm/providers/perplexity/capabilities.rb', line 61 def model_type(_model_id) 'chat' end |
.output_price_for(model_id) ⇒ Object
28 29 30 |
# File 'lib/ruby_llm/providers/perplexity/capabilities.rb', line 28 def output_price_for(model_id) PRICES.dig(model_family(model_id), :output) || 1.0 end |
.pricing_for(model_id) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ruby_llm/providers/perplexity/capabilities.rb', line 89 def pricing_for(model_id) family = model_family(model_id) prices = PRICES.fetch(family, { input: 1.0, output: 1.0 }) standard_pricing = { input_per_million: prices[:input], output_per_million: prices[:output] } standard_pricing[:citation_per_million] = prices[:citation] if prices[:citation] standard_pricing[:reasoning_per_million] = prices[:reasoning] if prices[:reasoning] standard_pricing[:search_per_thousand] = prices[:search_queries] if prices[:search_queries] { text_tokens: { standard: standard_pricing } } end |
.supports_functions?(_model_id) ⇒ Boolean
39 40 41 |
# File 'lib/ruby_llm/providers/perplexity/capabilities.rb', line 39 def supports_functions?(_model_id) false end |
.supports_json_mode?(_model_id) ⇒ Boolean
43 44 45 |
# File 'lib/ruby_llm/providers/perplexity/capabilities.rb', line 43 def supports_json_mode?(_model_id) true end |
.supports_vision?(model_id) ⇒ Boolean
32 33 34 35 36 37 |
# File 'lib/ruby_llm/providers/perplexity/capabilities.rb', line 32 def supports_vision?(model_id) case model_id when /sonar-reasoning-pro/, /sonar-reasoning/, /sonar-pro/, /sonar/ then true else false end end |