From 49e0a36a5164fccb31ab05acd3cd226524f68883 Mon Sep 17 00:00:00 2001 From: Simon Klinkert Date: Tue, 5 Nov 2024 16:06:42 +0100 Subject: [PATCH] add readme --- tools/perplexity/README.md | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tools/perplexity/README.md diff --git a/tools/perplexity/README.md b/tools/perplexity/README.md new file mode 100644 index 000000000..59628f175 --- /dev/null +++ b/tools/perplexity/README.md @@ -0,0 +1,62 @@ + +# 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 +} +``` \ No newline at end of file