Skip to main content
本页面将帮助您开始使用 Perplexity 聊天模型. 有关所有 ChatPerplexity 功能和配置的详细文档,请前往 API reference.

概述

集成详情

模型功能

设置

要访问 Perplexity 模型,您需要创建一个 Perplexity 账户,获取 API 密钥,并安装 langchain-perplexity 集成包。

凭证

前往 this page 注册 Perplexity 并生成 API 密钥。 完成后设置 PPLX_API_KEY 环境变量:
要启用模型调用的自动追踪,请设置您的 LangSmith API key:
The code provided assumes that your PPLX_API_KEY is set in your environment variables. If you would like to manually specify your API key and also choose a different model, you can use the following code:
You can check the list of available Perplexity models. For reproducibility, we can set the API key dynamically by taking it as an input in this notebook.
You can format and structure the prompts like you would typically. In the following example, we ask the model to tell us a joke about cats.

Using perplexity-specific parameters through ChatPerplexity

You can also use Perplexity-specific parameters through the ChatPerplexity class. For example, parameters like search_domain_filter, return_images, return_related_questions or search_recency_filter using the extra_body parameter as shown below:

Accessing the search results metadata

Perplexity often provides a list of the web pages it consulted (“search_results”). You don’t need to pass any special parameter—the list is placed in response.additional_kwargs["search_results"].

ChatPerplexity also supports streaming functionality

ChatPerplexity supports structured outputs for tier 3+ users