perplexity

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package perplexity provides integration with Perplexity AI's API for AI agents.

Perplexity AI functions as an AI-powered search engine that indexes, analyzes, and summarizes content from across the internet. This package allows you to integrate Perplexity's capabilities into your AI agents to enrich them with up-to-date web data.

Example usage:

llm, err := openai.New(
	openai.WithModel("gpt-4-mini"),
	openai.WithCallback(callbacks.LogHandler{}),
)
if err != nil {
	return err
}

// Create a new Perplexity instance
perpl, err := perplexity.New(
	perplexity.WithModel(perplexity.ModelLlamaSonarSmall),
	perplexity.WithAPIKey("your-api-key"), // Optional: defaults to PERPLEXITY_API_KEY env var
)
if err != nil {
	return err
}

// Add Perplexity as a tool for your agent
agentTools := []tools.Tool{
	perpl,
}

// Create and use the agent
toolAgent := agents.NewOneShotAgent(llm,
	agentTools,
	agents.WithMaxIterations(2),
)
executor := agents.NewExecutor(toolAgent)

answer, err := chains.Run(context.Background(), executor, "your question here")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

type Model string

Model represents a Perplexity AI model type.

const (
	// ModelSonar is the lightweight, cost-effective search model with grounding.
	ModelSonar Model = "sonar"
	// ModelSonarReasoning is the fast, real-time reasoning model for quick problem-solving.
	ModelSonarReasoning Model = "sonar-reasoning"
	// ModelSonarDeepResearch is the expert-level research model for comprehensive reports.
	ModelSonarDeepResearch Model = "sonar-deep-research"
	// Deprecated models - kept for backward compatibility
	ModelLlamaSonarSmall Model = "sonar"               // Redirects to sonar
	ModelLlamaSonarLarge Model = "sonar-reasoning"     // Redirects to sonar-reasoning
	ModelLlamaSonarHuge  Model = "sonar-deep-research" // Redirects to sonar-deep-research
)

Model pricing overview: https://docs.perplexity.ai/guides/pricing

type Option

type Option func(*options)

Option is a function that modifies the options for the Perplexity AI tool.

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets the API key for Perplexity AI.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient sets the HTTP client for Perplexity AI.

func WithModel

func WithModel(model Model) Option

WithModel sets the model to be used by Perplexity AI.

type Tool

type Tool struct {
	CallbacksHandler callbacks.Handler
	// contains filtered or unexported fields
}

Tool implements the Perplexity AI integration.

func New

func New(opts ...Option) (*Tool, error)

New creates a new instance of the Perplexity AI tool with the given options.

func (*Tool) Call

func (t *Tool) Call(ctx context.Context, input string) (string, error)

Call executes a query against the Perplexity AI model and returns the response.

func (*Tool) Description

func (t *Tool) Description() string

Description returns a description of the Perplexity AI tool's capabilities.

func (*Tool) Name

func (t *Tool) Name() string

Name returns the name of the tool.

Jump to

Keyboard shortcuts

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