本页还没有译文
本页 19 段还没译成한국어,下面显示的是英文原文。PerplexitySearchResults integration
还没翻译译自英文(docs.langchain.com)本页 19 段都还没译
The Perplexity Search API returns real-time, grounded web search results. PerplexitySearchResults is a LangChain tool wrapper that lets agents query the API and receive a JSON array of search results.
Overview
Integration details
| Class | Package | PY support | Version |
|---|---|---|---|
PerplexitySearchResults | @langchain/perplexity | ✅ |
Setup
The integration lives in the @langchain/perplexity package:
npm install @langchain/perplexity @langchain/coreyarn add @langchain/perplexity @langchain/corepnpm add @langchain/perplexity @langchain/coreCredentials
Set up a Perplexity API key and set it as an environment variable named PERPLEXITY_API_KEY:
process.env.PERPLEXITY_API_KEY = "your-api-key";It's also helpful (but not needed) to set up LangSmith for best-in-class observability:
process.env.LANGSMITH_TRACING = "true";
process.env.LANGSMITH_API_KEY = "your-api-key";Instantiation
import { PerplexitySearchResults } from "@langchain/perplexity";
const tool = new PerplexitySearchResults({
maxResults: 5,
// searchDomainFilter: ["wikipedia.org"],
// searchRecencyFilter: "week",
});Constructor options include maxResults, country, searchDomainFilter, searchRecencyFilter, searchAfterDate, and searchBeforeDate. See the Perplexity Search API parameters for details.
Invocation
Direct call
const result = await tool.invoke("Who won the most recent FIFA World Cup?");
console.log(result);The tool returns a JSON-encoded array of search results, each with title, url, snippet, date, and last_updated.
Use with an agent
import { ChatAnthropic } from "@langchain/anthropic";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
const llm = new ChatAnthropic({ model: "claude-haiku-4-5" });
const agent = createReactAgent({
llm,
tools: [tool],
});
const response = await agent.invoke({
messages: [
{ role: "user", content: "What's the latest news on the Mars Sample Return mission?" },
],
});API reference
For detailed documentation of all PerplexitySearchResults features and configurations head to the API reference.