Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel
Michael fc4a6bbc7d
docs(examples): update model references from gpt-4o-mini to gpt-4.1-mini (#4289)
2 months ago
..
1100ed924f
chore(providers): improve Perplexity API integration (#3990)
3 months ago
1100ed924f
chore(providers): improve Perplexity API integration (#3990)
3 months ago
1100ed924f
chore(providers): improve Perplexity API integration (#3990)
3 months ago
1100ed924f
chore(providers): improve Perplexity API integration (#3990)
3 months ago
fc4a6bbc7d
docs(examples): update model references from gpt-4o-mini to gpt-4.1-mini (#4289)
2 months ago

README.md

You have to be logged in to leave a comment. Sign In

perplexity.ai-example (Perplexity API Examples)

This example demonstrates how to use Perplexity's search-augmented chat models to get up-to-date answers with citations, structured outputs, and specialized reasoning.

You can run this example with:

npx promptfoo@latest init --example perplexity.ai-example

Features Demonstrated

  • Real-time web search with academic citations
  • Multiple specialized models for different use cases
  • Structured outputs (JSON schema and regex patterns)
  • Date-range and location-based search filtering
  • Search domain filtering for trusted sources
  • Chain of thought (CoT) reasoning
  • Deep research capabilities

Environment Variables

This example requires the following environment variables:

  • PERPLEXITY_API_KEY - Your Perplexity API key from Perplexity Settings
  • OPENAI_API_KEY - Your OpenAI API key (for comparison model in basic example)

You can set these in a .env file or directly in your environment:

export PERPLEXITY_API_KEY=your_api_key_here
export OPENAI_API_KEY=your_api_key_here

Example Configurations

This example includes multiple configuration files to demonstrate different Perplexity features:

1. Basic Model Comparison (promptfooconfig.yaml)

Compares different Perplexity search models against a traditional non-search model (GPT-4o-mini):

  • sonar: Lightweight search model
  • sonar-pro: Advanced search model with high context
  • sonar-reasoning: Fast reasoning model with step-by-step thinking
npx promptfoo@latest eval -c promptfooconfig.yaml

2. Structured Outputs (promptfooconfig.structured-output.yaml)

Demonstrates Perplexity's structured output capabilities:

  • JSON schema enforcement for movie information
  • Regex pattern matching for postal codes
npx promptfoo@latest eval -c promptfooconfig.structured-output.yaml

3. Advanced Search Filters (promptfooconfig.search-filters.yaml)

Shows how to use advanced search filtering options:

  • Date range filtering for time-sensitive queries
  • Location-based results for geographical context
  • Domain filtering for trusted sources
npx promptfoo@latest eval -c promptfooconfig.search-filters.yaml

4. Research and Reasoning (promptfooconfig.research-reasoning.yaml)

Demonstrates specialized models for research and reasoning:

  • sonar-deep-research: Comprehensive research model
  • sonar-reasoning-pro: Advanced reasoning with Chain of Thought
  • r1-1776: Offline model without search capabilities
npx promptfoo@latest eval -c promptfooconfig.research-reasoning.yaml

Usage

After initializing the example, you can run any of the configurations:

cd perplexity.ai-example
npx promptfoo@latest eval -c <config-file.yaml>
npx promptfoo@latest view

What You'll Learn

These examples will show you how to:

  • Use different Perplexity models for specific tasks
  • Control search parameters for better results
  • Get structured outputs in specific formats
  • Utilize location and date-based filtering
  • Leverage specialized research and reasoning capabilities
  • Compare search-augmented models with traditional models
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...