Documentation
¶
Overview ¶
Package perplexity provides Perplexity's LLM services: the Agent API, which answers with web search over the OpenAI Responses protocol, and the Sonar chat completions API, which Perplexity no longer supports.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAgentLLM ¶ added in v0.3.0
func NewAgentLLM(cfg AgentConfig) *responses.HTTPService
NewAgentLLM builds a service for Perplexity's Agent API.
The Agent API answers questions with web search, using models from Perplexity and other providers. It speaks the OpenAI Responses protocol over HTTP, so function calling and multi-turn context work as they do with the Responses HTTP service.
By default the service uses openai/gpt-5.6-luna with web search on. When neither Preset nor Reasoning is set, it sends Perplexity's "fast" preset, its lowest-latency configuration, with the model in place of the preset's own, and logs that it did for each model. Answers can carry citation markers such as "[1]".
func NewLLM
deprecated
func NewLLM(cfg chat.LLMConfig) *chat.LLMService
NewLLM builds a service for Perplexity's Sonar chat completions API. Perplexity speaks the OpenAI chat-completions API there, with two departures from it: it has no developer role, and it is stricter than OpenAI about the shape of a conversation (which its adapter settles).
Deprecated: Perplexity has ended support for Sonar chat completions in favor of its Agent API. Use NewAgentLLM instead.
Types ¶
type AgentConfig ¶ added in v0.3.0
type AgentConfig struct {
// APIKey is the Perplexity API key. Required.
APIKey string `validate:"required"`
// BaseURL overrides the API base; empty uses the hosted Agent API.
BaseURL string
// Model is the model id, such as "openai/gpt-5.5" or
// "anthropic/claude-haiku-4-5"; empty uses openai/gpt-5.6-luna. With a
// Preset, it replaces the preset's own model.
Model string
// PresetModel leaves the model to the Preset: the request names none, and
// Model is ignored. It needs a Preset.
PresetModel bool
// Preset is a Perplexity preset that sets the model, its instructions, its
// search budget and how much it reasons, such as "fast", "low", "medium",
// "high" or "xhigh". Empty sends none, and a request with no Reasoning
// either then gets the "fast" preset.
Preset string
// NoWebSearch stops the service offering the web_search tool on every
// request, alongside any tools from the context. A preset searches the web
// whatever this is set to.
NoWebSearch bool
// MaxSteps is the maximum number of search and reasoning steps per
// response; 0 leaves Perplexity's default.
MaxSteps int `validate:"gte=0"`
// Instructions is the system prompt, sent alongside the input rather than as
// a message. A system message on the context takes precedence.
Instructions string
// MaxOutputTokens caps the response length; 0 omits it. Anthropic models
// need it set.
MaxOutputTokens int
// Temperature is the sampling temperature; nil omits it.
Temperature *float64
// TopP is the nucleus-sampling parameter; nil omits it.
TopP *float64
// Reasoning configures how much the model reasons. Set, it replaces the
// "fast" preset otherwise sent when there is no Preset.
Reasoning *responses.ReasoningConfig
// Extra sets arbitrary additional request fields not modeled above, applied
// to every request. They override the modeled fields on conflict.
Extra map[string]any
}
AgentConfig configures the Agent API service. The sampling controls are pointers so a deliberate zero is distinguishable from "unset"; a nil value is omitted from the request, leaving the API default.
func (AgentConfig) Validate ¶ added in v0.3.0
func (c AgentConfig) Validate() error
Validate reports whether the configuration is usable.