Class: RubyLLM::Protocols::Perplexity::Router

Inherits:
ChatCompletions show all
Defined in:
lib/ruby_llm/protocols/perplexity/router.rb

Overview

Perplexity Router's Chat Completions dialect.

Instance Attribute Summary

Attributes inherited from RubyLLM::Protocol

#config, #connection, #model, #provider

Instance Method Summary collapse

Methods inherited from RubyLLM::Protocol

abstract, #animate_later, #apply_compaction, #apply_compaction_headers, #apply_end_user, #cache_content, #compact, #complete, #count_tokens, #delete_cache, #embed, #extend_cache, #find_cache, #initialize, #list_models, #moderate, #ocr, #paint, #parse_error, #parse_image_responses, #post_image, #post_video, #preprocess_message, #raise_transcription_streaming_unsupported, #refresh_video_job, #render_embedding, #render_transcription_options, #render_video_extension_payload, #rerank, #server_tool_aliases, #speak, #stream_speech, #stream_speech_response, #stream_transcription, #supports_embedding_media?, #tokenize, #tool_approval_response, #transcribe, #video_extension_attachment, #video_extension_url, #video_request_url

Methods included from RubyLLM::Protocol::BinaryStreaming

#stream_binary

Methods included from RubyLLM::Protocol::Streaming

build_on_data_handler, build_stream_error_response, error_chunk?, failed_http_status, faraday_1?, handle_data, handle_error_chunk, handle_error_event, handle_failed_response, handle_json_error_chunk, handle_sse, handle_stream, json_error_payload?, parse_error_from_json, parse_streaming_error, process_stream_chunk, raise_stream_error, stream_events, stream_response, stream_state

Constructor Details

This class inherits a constructor from RubyLLM::Protocol

Instance Method Details

#completion_urlObject



13
14
15
# File 'lib/ruby_llm/protocols/perplexity/router.rb', line 13

def completion_url
  @provider.router_url('chat/completions')
end

#format_audio(audio) ⇒ Object



32
33
34
35
36
# File 'lib/ruby_llm/protocols/perplexity/router.rb', line 32

def format_audio(audio)
  raise UnsupportedAttachmentError, audio.mime_type unless %w[mp3 wav].include?(audio.format)

  super
end

#renderObject



17
18
19
20
21
22
# File 'lib/ruby_llm/protocols/perplexity/router.rb', line 17

def render(...)
  super.tap do |payload|
    validate_router_options(payload)
    validate_router_tools(payload[:tools])
  end
end

#render_payload(messages, schema: nil, **options) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/ruby_llm/protocols/perplexity/router.rb', line 24

def render_payload(messages, schema: nil, **options)
  if schema && schema[:strict] == false
    raise ArgumentError, 'Perplexity Router requires strict structured output'
  end

  super(messages, schema: schema&.merge(strict: true), **options)
end