> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-docs-zh.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# PerplexitySearchResults 集成

> 使用 LangChain JavaScript 集成 PerplexitySearchResults 工具。

[Perplexity Search API](https://docs.perplexity.ai/docs/search/quickstart) 返回实时、有依据的网页搜索结果。`PerplexitySearchResults` 是一个 LangChain [工具](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/tools.md) 包装器，允许智能体查询该 API 并接收一个搜索结果的 JSON 数组。

## 概述

### 集成细节

| 类 | 包 | [PY 支持](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/tools/perplexity_search.md) | 版本 |
| :- | :- | :-: | :-: |
| [`PerplexitySearchResults`](https://reference.langchain.com/javascript/langchain-perplexity/PerplexitySearchResults) | [`@langchain/perplexity`](https://www.npmjs.com/package/@langchain/perplexity) | ✅ | ![NPM - 版本](https://img.shields.io/npm/v/@langchain/perplexity?style=flat-square\&label=%20&) |

## 设置

集成存在于 `@langchain/perplexity` 包中：

```bash npm theme={null}
npm install @langchain/perplexity @langchain/core
```

```bash yarn theme={null}
yarn add @langchain/perplexity @langchain/core
```

```bash pnpm theme={null}
pnpm add @langchain/perplexity @langchain/core
```

### 凭证

设置一个 [Perplexity API 密钥](https://www.perplexity.ai/account/api/keys) 并将其设置为名为 `PERPLEXITY_API_KEY` 的环境变量：

```typescript theme={null}
process.env.PERPLEXITY_API_KEY = "your-api-key";
```

设置 [LangSmith](https://smith.langchain.com/)（但非必需）以获得最佳级别的可观察性：

```typescript theme={null}
process.env.LANGSMITH_TRACING = "true";
process.env.LANGSMITH_API_KEY = "your-api-key";
```

## 实例化

```typescript theme={null}
import { PerplexitySearchResults } from "@langchain/perplexity";

const tool = new PerplexitySearchResults({
  maxResults: 5,
  // searchDomainFilter: ["wikipedia.org"],
  // searchRecencyFilter: "week",
});
```

构造函数选项包括 `maxResults`、`country`、`searchDomainFilter`、`searchRecencyFilter`、`searchAfterDate` 和 `searchBeforeDate`。详情请参阅 [Perplexity Search API 参数](https://docs.perplexity.ai/docs/search/quickstart)。

## 调用

### 直接调用

```typescript theme={null}
const result = await tool.invoke("Who won the most recent FIFA World Cup?");
console.log(result);
```

该工具返回一个 JSON 编码的搜索结果数组，每个结果包含 `title`、`url`、`snippet`、`date` 和 `last_updated`。

### 与智能体一起使用

```typescript theme={null}
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 参考

所有 `PerplexitySearchResults` 功能和配置的详细文档请参考 [API 参考](https://reference.langchain.com/javascript/langchain-perplexity/PerplexitySearchResults)。

***

> 官方原文：[src/oss/javascript/integrations/tools/perplexity\_search.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/javascript/integrations/tools/perplexity_search.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.