add doc.go

This commit is contained in:
Simon Klinkert
2025-01-05 22:34:07 +01:00
parent ff93722af1
commit dca2a9c973
2 changed files with 40 additions and 62 deletions
-62
View File
@@ -1,62 +0,0 @@
# Perplexity Tool Integration for Agents
Use perplexity in your AI Agent to enrich it with data from the web.
Full code example:
```go
package main
import (
"context"
"fmt"
"os"
"github.com/tmc/langchaingo/agents"
"github.com/tmc/langchaingo/callbacks"
"github.com/tmc/langchaingo/chains"
"github.com/tmc/langchaingo/llms/openai"
"github.com/tmc/langchaingo/tools"
"github.com/tmc/langchaingo/tools/perplexity"
)
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func run() error {
llm, err := openai.New(
openai.WithModel("gpt-4o-mini"),
openai.WithCallback(callbacks.LogHandler{}),
)
if err != nil {
return err
}
perpl, err := perplexity.NewPerplexity(perplexity.ModelLlamaSonarSmall)
if err != nil {
return err
}
agentTools := []tools.Tool{
perpl,
}
agent := agents.NewOneShotAgent(llm,
agentTools,
agents.WithMaxIterations(2),
)
executor := agents.NewExecutor(agent)
question := "what's the latest and best LLM on the market at the moment?"
answer, err := chains.Run(context.Background(), executor, question)
fmt.Println(answer)
return err
}
```
+40
View File
@@ -0,0 +1,40 @@
// 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.NewPerplexity(
// 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
// agent := agents.NewOneShotAgent(llm,
// agentTools,
// agents.WithMaxIterations(2),
// )
// executor := agents.NewExecutor(agent)
//
// answer, err := chains.Run(context.Background(), executor, "your question here")
package perplexity