0d3cb498a3
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
107 lines
3.2 KiB
Markdown
107 lines
3.2 KiB
Markdown
# provider-perplexity (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:
|
|
|
|
```bash
|
|
npx promptfoo@latest init --example provider-perplexity
|
|
cd provider-perplexity
|
|
```
|
|
|
|
## 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](https://www.perplexity.ai/settings/api)
|
|
- `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:
|
|
|
|
```bash
|
|
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
|
|
|
|
```bash
|
|
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
|
|
|
|
```bash
|
|
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
|
|
|
|
```bash
|
|
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
|
|
|
|
```bash
|
|
npx promptfoo@latest eval -c promptfooconfig.research-reasoning.yaml
|
|
```
|
|
|
|
## Usage
|
|
|
|
After initializing the example, you can run any of the configurations:
|
|
|
|
```bash
|
|
cd provider-perplexity
|
|
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
|