Class: RubyLLM::Providers::Perplexity
- Inherits:
-
RubyLLM::Provider
- Object
- RubyLLM::Provider
- RubyLLM::Providers::Perplexity
- Defined in:
- lib/ruby_llm/providers/perplexity.rb,
lib/ruby_llm/providers/perplexity/chat.rb,
lib/ruby_llm/providers/perplexity/media.rb,
lib/ruby_llm/providers/perplexity/models.rb,
lib/ruby_llm/providers/perplexity/embeddings.rb
Overview
Perplexity API integration.
Defined Under Namespace
Modules: Chat, Embeddings, Media, Models Classes: ChatCompletions
Constant Summary
Constants included from Support::Inspectable
Support::Inspectable::TRUNCATE_AT
Instance Attribute Summary
Attributes inherited from RubyLLM::Provider
Class Method Summary collapse
Instance Method Summary collapse
- #api_base ⇒ Object
- #headers ⇒ Object
- #parse_error(response) ⇒ Object
-
#router_url(operation) ⇒ Object
:nodoc:.
Methods inherited from RubyLLM::Provider
#animate_later, #assume_models_exist?, assume_models_exist?, #batch_cost, #batch_cost_amounts, #batch_cost_multiplier, #batch_protocol_name, #batch_results, #batch_status, #batches?, #cache_content, #cancel_batch, #capabilities, capabilities, #compact, #complete, #configuration_requirements, configured?, #configured?, configured_providers, configured_remote_providers, #count_tokens, #create_batch, #delete_cache, display_name, #download_file, #embed, #extend_cache, #files?, #find_batch, #find_cache, #find_file, #find_research_job, #initialize, #list_file_uris, #list_models, local?, #local?, local_providers, #long_context_pricing?, model_registry_files, model_required?, models_dev_alias, models_dev_model_id, #moderate, #name, #ocr, #paint, #preprocess_message, protocol, #protocol_for, protocols, #protocols, providers, register, remote?, remote_providers, #render, #render_embedding, #rerank, #research_later, resolve, resolve!, resolve_registry_id, #retry_delay, #slug, #speak, #tokenize, #tool_approval_response, #transcribe, #upload_file
Methods included from Support::Inspectable
#full_inspect, #inspect, #pretty_print
Constructor Details
This class inherits a constructor from RubyLLM::Provider
Class Method Details
.configuration_options ⇒ Object
50 51 52 |
# File 'lib/ruby_llm/providers/perplexity.rb', line 50 def %i[perplexity_api_key perplexity_api_base] end |
.configuration_requirements ⇒ Object
54 55 56 |
# File 'lib/ruby_llm/providers/perplexity.rb', line 54 def configuration_requirements %i[perplexity_api_key] end |
Instance Method Details
#api_base ⇒ Object
18 19 20 |
# File 'lib/ruby_llm/providers/perplexity.rb', line 18 def api_base @config.perplexity_api_base || 'https://api.perplexity.ai' end |
#headers ⇒ Object
26 27 28 29 30 31 |
# File 'lib/ruby_llm/providers/perplexity.rb', line 26 def headers { 'Authorization' => "Bearer #{@config.perplexity_api_key}", 'Content-Type' => 'application/json' } end |
#parse_error(response) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby_llm/providers/perplexity.rb', line 33 def parse_error(response) body = parse_error_body(response) return unless body # If response is HTML (Perplexity returns HTML for auth errors) if body.is_a?(String) && body.include?('<html>') && body.include?('<title>') title_match = body.match(%r{<title>(.+?)</title>}) if title_match = title_match[1] = .sub(/^\d+\s+/, '') return end end super end |
#router_url(operation) ⇒ Object
:nodoc:
22 23 24 |
# File 'lib/ruby_llm/providers/perplexity.rb', line 22 def router_url(operation) # :nodoc: "#{api_base.delete_suffix('/').delete_suffix('/router/v1')}/router/v1/#{operation}" end |