Documentation
¶
Overview ¶
Package perplexity provides a Perplexity Search API provider implementation for Iris.
Index ¶
- Constants
- Variables
- func GetModelInfo(id core.ModelID) *core.ModelInfo
- type Config
- type JSONSchema
- type Option
- type Perplexity
- func (p *Perplexity) Chat(ctx context.Context, req *core.ChatRequest) (*core.ChatResponse, error)
- func (p *Perplexity) ID() string
- func (p *Perplexity) Models() []core.ModelInfo
- func (p *Perplexity) StreamChat(ctx context.Context, req *core.ChatRequest) (*core.ChatStream, error)
- func (p *Perplexity) Supports(feature core.Feature) bool
- type ResponseFormat
- type SearchResult
- type WebSearchOptions
Constants ¶
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.
const DefaultAPIKeyEnvVar = "PERPLEXITY_API_KEY"
DefaultAPIKeyEnvVar is the environment variable name for the Perplexity API key.
const DefaultBaseURL = "https://api.perplexity.ai"
DefaultBaseURL is the default Perplexity API base URL.
Variables ¶
var ErrAPIKeyNotFound = errors.New("perplexity: PERPLEXITY_API_KEY environment variable not set")
ErrAPIKeyNotFound is returned when the API key environment variable is not set.
var ErrToolArgsInvalidJSON = errors.New("tool args invalid json")
ErrToolArgsInvalidJSON is returned when tool call arguments contain invalid JSON.
Functions ¶
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 WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client.
func WithHeader ¶
WithHeader adds an extra header to include in requests.
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 ¶
func (p *Perplexity) Chat(ctx context.Context, req *core.ChatRequest) (*core.ChatResponse, error)
Chat sends a non-streaming chat request.
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.
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.