perplexity

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2025 License: MIT Imports: 7 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 (
	// ModelLlamaSonarSmall is the small version of the Llama Sonar model.
	ModelLlamaSonarSmall Model = "llama-3.1-sonar-small-128k-online"
	// ModelLlamaSonarLarge is the large version of the Llama Sonar model.
	ModelLlamaSonarLarge Model = "llama-3.1-sonar-large-128k-online"
	// ModelLlamaSonarHuge is the huge version of the Llama Sonar model.
	ModelLlamaSonarHuge Model = "llama-3.1-sonar-huge-128k-online"
)

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