perplexity

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package perplexity provides a Perplexity Search API provider implementation for Iris.

Index

Constants

View Source
const (
	// Search Models
	ModelSonar    core.ModelID = "sonar"     // Lightweight, cost-effective search with grounding
	ModelSonarPro core.ModelID = "sonar-pro" // Advanced search with Pro Search support

	// Reasoning Models
	ModelSonarReasoningPro core.ModelID = "sonar-reasoning-pro" // Chain of Thought reasoning with search

	// Research Models
	ModelSonarDeepResearch core.ModelID = "sonar-deep-research" // Comprehensive research and report generation
)

Model constants for Perplexity models.

View Source
const DefaultAPIKeyEnvVar = "PERPLEXITY_API_KEY"

DefaultAPIKeyEnvVar is the environment variable name for the Perplexity API key.

View Source
const DefaultBaseURL = "https://api.perplexity.ai"

DefaultBaseURL is the default Perplexity API base URL.

Variables

View Source
var ErrAPIKeyNotFound = errors.New("perplexity: PERPLEXITY_API_KEY environment variable not set")

ErrAPIKeyNotFound is returned when the API key environment variable is not set.

View Source
var ErrToolArgsInvalidJSON = errors.New("tool args invalid json")

ErrToolArgsInvalidJSON is returned when tool call arguments contain invalid JSON.

Functions

func GetModelInfo

func GetModelInfo(id core.ModelID) *core.ModelInfo

GetModelInfo returns the ModelInfo for a given model ID, or nil if not found.

Types

type Config

type Config struct {
	// APIKey is the Perplexity API key (required).
	// Stored as Secret to prevent accidental logging.
	APIKey core.Secret

	// BaseURL is the API base URL. Defaults to https://api.perplexity.ai
	BaseURL string

	// HTTPClient is the HTTP client to use. Defaults to http.DefaultClient.
	HTTPClient *http.Client

	// Headers contains optional extra headers to include in requests.
	Headers http.Header

	// Timeout is the optional request timeout.
	Timeout time.Duration
}

Config holds configuration for the Perplexity provider.

type JSONSchema

type JSONSchema struct {
	Name   string                 `json:"name,omitempty"`
	Schema map[string]interface{} `json:"schema"`
}

JSONSchema for structured output schema.

type Option

type Option func(*Config)

Option configures the Perplexity provider.

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL sets the API base URL.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets a custom HTTP client.

func WithHeader

func WithHeader(key, value string) Option

WithHeader adds an extra header to include in requests.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the request timeout.

type Perplexity

type Perplexity struct {
	// contains filtered or unexported fields
}

Perplexity is an LLM provider implementation for the Perplexity Search API. Perplexity is safe for concurrent use.

func New

func New(apiKey string, opts ...Option) *Perplexity

New creates a new Perplexity provider with the given API key and options.

func NewFromEnv added in v0.10.0

func NewFromEnv(opts ...Option) (*Perplexity, error)

NewFromEnv creates a new Perplexity provider using the PERPLEXITY_API_KEY environment variable. This is a convenience factory for quick setup:

provider, err := perplexity.NewFromEnv()
if err != nil {
    log.Fatal(err)
}
client := core.NewClient(provider)

func (*Perplexity) Chat

Chat sends a non-streaming chat request.

func (*Perplexity) ID

func (p *Perplexity) ID() string

ID returns the provider identifier.

func (*Perplexity) Models

func (p *Perplexity) Models() []core.ModelInfo

Models returns the list of available models.

func (*Perplexity) StreamChat

func (p *Perplexity) StreamChat(ctx context.Context, req *core.ChatRequest) (*core.ChatStream, error)

StreamChat sends a streaming chat request.

func (*Perplexity) Supports

func (p *Perplexity) Supports(feature core.Feature) bool

Supports reports whether the provider supports the given feature.

type ResponseFormat

type ResponseFormat struct {
	Type       string      `json:"type"` // text|json_schema
	JSONSchema *JSONSchema `json:"json_schema,omitempty"`
}

ResponseFormat for structured outputs.

type SearchResult

type SearchResult struct {
	Title       string `json:"title"`
	URL         string `json:"url"`
	Date        string `json:"date,omitempty"`
	LastUpdated string `json:"last_updated,omitempty"`
	Snippet     string `json:"snippet"`
	Source      string `json:"source"` // "web"
}

SearchResult represents a search result from Perplexity.

type WebSearchOptions

type WebSearchOptions struct {
	SearchType string `json:"search_type,omitempty"` // fast|pro|auto
}

WebSearchOptions configures Pro Search behavior.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL