perplexity

package
v0.1.13-update.3 Latest Latest
Warning

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

Go to latest
Published: May 13, 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.ModelSonar),
	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 (
	// ModelSonarDeepResearch is the deep research model with 128k context window for chat completion.
	ModelSonarDeepResearch Model = "sonar-deep-research"
	// ModelSonarReasoningPro is the reasoning pro model with 128k context window for chat completion.
	ModelSonarReasoningPro Model = "sonar-reasoning-pro"
	// ModelSonarReasoning is the reasoning model with 128k context window for chat completion.
	ModelSonarReasoning Model = "sonar-reasoning"
	// ModelSonarPro is the pro model with 200k context window for chat completion.
	ModelSonarPro Model = "sonar-pro"
	// ModelSonar is the standard model with 128k context window for chat completion.
	ModelSonar Model = "sonar"
	// ModelR11776 is the r1-1776 model.
	ModelR11776 Model = "r1-1776"
)

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 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