Skip to content

Feat: Perplexity support #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RubyLLM.configure do |config|
config.anthropic_api_key = ENV.fetch('ANTHROPIC_API_KEY', nil)
config.gemini_api_key = ENV.fetch('GEMINI_API_KEY', nil)
config.deepseek_api_key = ENV.fetch('DEEPSEEK_API_KEY', nil)
config.perplexity_api_key = ENV.fetch('PERPLEXITY_API_KEY', nil)
config.openrouter_api_key = ENV.fetch('OPENROUTER_API_KEY', nil)
config.ollama_api_base = ENV.fetch('OLLAMA_API_BASE', nil)
config.bedrock_api_key = ENV.fetch('AWS_ACCESS_KEY_ID', nil)
Expand Down
2 changes: 2 additions & 0 deletions lib/ruby_llm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'openai' => 'OpenAI',
'api' => 'API',
'deepseek' => 'DeepSeek',
'perplexity' => 'Perplexity',
'bedrock' => 'Bedrock',
'openrouter' => 'OpenRouter',
'pdf' => 'PDF'
Expand Down Expand Up @@ -80,6 +81,7 @@ def logger
RubyLLM::Provider.register :anthropic, RubyLLM::Providers::Anthropic
RubyLLM::Provider.register :gemini, RubyLLM::Providers::Gemini
RubyLLM::Provider.register :deepseek, RubyLLM::Providers::DeepSeek
RubyLLM::Provider.register :perplexity, RubyLLM::Providers::Perplexity
RubyLLM::Provider.register :bedrock, RubyLLM::Providers::Bedrock
RubyLLM::Provider.register :openrouter, RubyLLM::Providers::OpenRouter
RubyLLM::Provider.register :ollama, RubyLLM::Providers::Ollama
Expand Down
20 changes: 14 additions & 6 deletions lib/ruby_llm/aliases.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,50 @@
"claude-2.0": {
"anthropic": "claude-2.0",
"openrouter": "anthropic/claude-2.0",
"perplexity": "perplexity.claude-2.0",
"bedrock": "anthropic.claude-v2:1:200k"
},
"claude-2.1": {
"anthropic": "claude-2.1",
"openrouter": "anthropic/claude-2.1",
"perplexity": "perplexity.claude-2.1",
"bedrock": "anthropic.claude-v2:1:200k"
},
"claude-3-5-haiku": {
"anthropic": "claude-3-5-haiku-20241022",
"openrouter": "anthropic/claude-3.5-haiku",
"bedrock": "anthropic.claude-3-5-haiku-20241022-v1:0"
"bedrock": "anthropic.claude-3-5-haiku-20241022-v1:0",
"perplexity": "perplexity.claude-3-5-haiku-20241022-v1:0"
},
"claude-3-5-sonnet": {
"anthropic": "claude-3-5-sonnet-20241022",
"openrouter": "anthropic/claude-3.5-sonnet",
"bedrock": "anthropic.claude-3-5-sonnet-20240620-v1:0:200k"
"bedrock": "anthropic.claude-3-5-sonnet-20240620-v1:0:200k",
"perplexity": "perplexity.claude-3-5-sonnet-20241022-v2:0"
},
"claude-3-7-sonnet": {
"anthropic": "claude-3-7-sonnet-20250219",
"openrouter": "anthropic/claude-3.7-sonnet",
"bedrock": "us.anthropic.claude-3-7-sonnet-20250219-v1:0"
"bedrock": "us.anthropic.claude-3-7-sonnet-20250219-v1:0",
"perplexity": "perplexity.claude-3-7-sonnet-20250219-v1:0"
},
"claude-3-haiku": {
"anthropic": "claude-3-haiku-20240307",
"openrouter": "anthropic/claude-3-haiku",
"bedrock": "anthropic.claude-3-haiku-20240307-v1:0:200k"
"bedrock": "anthropic.claude-3-haiku-20240307-v1:0:200k",
"perplexity": "perplexity.claude-3-haiku-20240307-v1:0"
},
"claude-3-opus": {
"anthropic": "claude-3-opus-20240229",
"openrouter": "anthropic/claude-3-opus",
"bedrock": "anthropic.claude-3-opus-20240229-v1:0:200k"
"bedrock": "anthropic.claude-3-opus-20240229-v1:0:200k",
"perplexity": "perplexity.claude-3-opus-20240229-v1:0"
},
"claude-3-sonnet": {
"anthropic": "claude-3-sonnet-20240229",
"openrouter": "anthropic/claude-3-sonnet",
"bedrock": "anthropic.claude-3-sonnet-20240229-v1:0:200k"
"bedrock": "anthropic.claude-3-sonnet-20240229-v1:0:200k",
"perplexity": "perplexity.claude-3-sonnet-20240229-v1:0"
},
"claude-opus-4": {
"anthropic": "claude-opus-4-20250514",
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_llm/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Configuration
:anthropic_api_key,
:gemini_api_key,
:deepseek_api_key,
:perplexity_api_key,
:bedrock_api_key,
:bedrock_secret_key,
:bedrock_region,
Expand Down
111 changes: 110 additions & 1 deletion lib/ruby_llm/models.json
Original file line number Diff line number Diff line change
Expand Up @@ -27660,5 +27660,114 @@
"response_format"
]
}
},
{
"id": "r1-1776",
"created_at": null,
"display_name": "R1-1776",
"provider": "perplexity",
"context_window": 128000,
"max_tokens": 4096,
"type": "chat",
"family": "r1_1776",
"supports_vision": false,
"supports_functions": false,
"supports_json_mode": true,
"input_price_per_million": 2.0,
"output_price_per_million": 8.0,
"metadata": {
"description": "R1-1776 is a version of the DeepSeek R1 model that has been post-trained to provide uncensored, unbiased, and factual information."
}
},
{
"id": "sonar",
"created_at": null,
"display_name": "Sonar",
"provider": "perplexity",
"context_window": 128000,
"max_tokens": 4096,
"type": "chat",
"family": "sonar",
"supports_vision": true,
"supports_functions": false,
"supports_json_mode": true,
"input_price_per_million": 1.0,
"output_price_per_million": 1.0,
"metadata": {
"description": "Lightweight offering with search grounding, quicker and cheaper than Sonar Pro."
}
},
{
"id": "sonar-deep-research",
"created_at": null,
"display_name": "Sonar Deep Research",
"provider": "perplexity",
"context_window": 128000,
"max_tokens": 4096,
"type": "chat",
"family": "sonar_deep_research",
"supports_vision": false,
"supports_functions": false,
"supports_json_mode": true,
"input_price_per_million": 2.0,
"output_price_per_million": 8.0,
"metadata": {
"description": "Deep Research conducts comprehensive, expert-level research and synthesizes it into accessible, actionable reports.",
"reasoning_price_per_million": 3.0
}
},
{
"id": "sonar-pro",
"created_at": null,
"display_name": "Sonar Pro",
"provider": "perplexity",
"context_window": 200000,
"max_tokens": 8192,
"type": "chat",
"family": "sonar_pro",
"supports_vision": true,
"supports_functions": false,
"supports_json_mode": true,
"input_price_per_million": 3.0,
"output_price_per_million": 15.0,
"metadata": {
"description": "Premier search offering with search grounding, supporting advanced queries and follow-ups."
}
},
{
"id": "sonar-reasoning",
"created_at": null,
"display_name": "Sonar Reasoning",
"provider": "perplexity",
"context_window": 128000,
"max_tokens": 4096,
"type": "chat",
"family": "sonar_reasoning",
"supports_vision": true,
"supports_functions": false,
"supports_json_mode": true,
"input_price_per_million": 1.0,
"output_price_per_million": 5.0,
"metadata": {
"description": "Reasoning model with Chain of Thought (CoT) capabilities."
}
},
{
"id": "sonar-reasoning-pro",
"created_at": null,
"display_name": "Sonar Reasoning Pro",
"provider": "perplexity",
"context_window": 128000,
"max_tokens": 8192,
"type": "chat",
"family": "sonar_reasoning_pro",
"supports_vision": true,
"supports_functions": false,
"supports_json_mode": true,
"input_price_per_million": 2.0,
"output_price_per_million": 8.0,
"metadata": {
"description": "Premier reasoning offering powered by DeepSeek R1 with Chain of Thought (CoT)."
}
}
]
]
38 changes: 38 additions & 0 deletions lib/ruby_llm/providers/perplexity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

module RubyLLM
module Providers
# Perplexity API integration. Handles chat completion, streaming,
# and Perplexity's unique features like citations.
module Perplexity
extend OpenAI
extend Perplexity::Chat
extend Perplexity::Models

module_function

def api_base(_config)
'https://api.perplexity.ai'
end

def headers(config)
{
'Authorization' => "Bearer #{config.perplexity_api_key}",
'Content-Type' => 'application/json'
}
end

def capabilities
Perplexity::Capabilities
end

def slug
'perplexity'
end

def configuration_requirements
%i[perplexity_api_key]
end
end
end
end
Loading