chore: import upstream snapshot with attribution
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

This commit is contained in:
wehub-resource-sync
2026-07-13 13:24:08 +08:00
commit 0d3cb498a3
5438 changed files with 1316560 additions and 0 deletions
+106
View File
@@ -0,0 +1,106 @@
# 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
@@ -0,0 +1,36 @@
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
description: Research and reasoning with Perplexity specialized models
prompts:
- 'Create a comprehensive report on {{research_topic}} with the latest findings and data.'
- 'Solve the following math problem, showing your step-by-step reasoning: {{math_problem}}'
providers:
- id: perplexity:sonar-deep-research
config:
temperature: 0.1
max_tokens: 4000
search_domain_filter: ['arxiv.org', 'researchgate.net', 'scholar.google.com']
web_search_options:
search_context_size: 'high'
# This provider will be used for the first prompt only
- id: perplexity:sonar-reasoning-pro
config:
temperature: 0.2
max_tokens: 3000
# This provider will be used for the second prompt only
- id: perplexity:r1-1776
config:
temperature: 0.2
max_tokens: 2000
# Offline model without search capabilities
tests:
- vars:
research_topic: 'advancements in protein folding algorithms in 2024'
math_problem: 'A ball is thrown upward from the ground with an initial velocity of 25 m/s. How high will the ball go and how long will it take to reach that height? (Use g = 9.8 m/s²)'
- vars:
research_topic: 'the impact of large language models on education'
math_problem: 'A cylindrical water tank has a radius of 3 meters and a height of 8 meters. It is being filled at a rate of 2 cubic meters per minute. How long will it take to fill the tank? (Use π = 3.14)'
@@ -0,0 +1,47 @@
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
description: Advanced search filters with Perplexity (date and location)
prompts:
- 'What were the major tech announcements during {{event}}?'
- 'What are the best {{food}} restaurants near {{location}}?'
providers:
- id: perplexity:sonar-pro
config:
temperature: 0.2
max_tokens: 1500
# Date range filters (only used with first prompt)
search_after_date_filter: '01/01/2024'
search_before_date_filter: '05/31/2024'
search_domain_filter: ['theverge.com', 'techcrunch.com', 'wired.com']
web_search_options:
search_context_size: 'high'
# This provider will be used for the first prompt only
- id: perplexity:sonar-pro
config:
temperature: 0.2
max_tokens: 1500
# Location-based search (only used with second prompt)
web_search_options:
user_location:
# San Francisco coordinates
latitude: 37.7749
longitude: -122.4194
country: 'US'
search_context_size: 'medium'
# This provider will be used for the second prompt only
tests:
- vars:
event: Google I/O 2024
food: sushi
location: downtown
- vars:
event: Apple WWDC 2024
food: pizza
location: financial district
- vars:
event: CES 2024
food: vegan
location: mission district
@@ -0,0 +1,51 @@
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
description: Structured outputs with Perplexity (JSON and regex)
prompts:
- 'Tell me about {{movie}}. Format your answer as a structured JSON object.'
- 'What is the postal code for {{city}}, {{country}}?'
providers:
- id: perplexity:sonar
config:
temperature: 0.1
max_tokens: 1000
usage_tier: 'medium' # For cost calculation
response_format:
type: 'json_schema'
json_schema:
schema:
type: 'object'
properties:
title: { type: 'string' }
director: { type: 'string' }
year: { type: 'integer' }
genres: { type: 'array', items: { type: 'string' } }
plot_summary: { type: 'string' }
required: ['title', 'director', 'year', 'genres', 'plot_summary']
# This provider will be used for the first prompt only
- id: perplexity:sonar
config:
temperature: 0.1
max_tokens: 150
usage_tier: 'low' # For cost calculation
response_format:
type: 'regex'
regex:
regex: '[0-9A-Z]{1,10}'
# This provider will be used for the second prompt only
tests:
- vars:
movie: Inception
city: Paris
country: France
- vars:
movie: The Matrix
city: Tokyo
country: Japan
- vars:
movie: Parasite
city: Sydney
country: Australia
@@ -0,0 +1,43 @@
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
description: Search-augmented responses with different Perplexity models
prompts:
- 'What are the latest scientific discoveries about {{topic}}? Please include citations.'
providers:
- id: openai:chat:gpt-5-mini
- id: perplexity:sonar
config:
temperature: 0.2
max_tokens: 1000
search_domain_filter: ['nature.com', 'science.org', 'newscientist.com']
search_recency_filter: 'month'
return_related_questions: true
usage_tier: 'low'
web_search_options:
search_context_size: 'medium'
- id: perplexity:sonar-pro
config:
temperature: 0.2
max_tokens: 2000
search_domain_filter: ['nature.com', 'science.org', 'newscientist.com']
search_recency_filter: 'month'
usage_tier: 'medium'
web_search_options:
search_context_size: 'high'
- id: perplexity:sonar-reasoning
config:
temperature: 0.3
max_tokens: 2500
search_domain_filter: ['nature.com', 'science.org', 'newscientist.com']
search_recency_filter: 'month'
usage_tier: 'high'
tests:
- vars:
topic: dark matter
- vars:
topic: quantum computing