langchain/libs/partners/perplexity
Inácio Nery ea8f2a05ba
feat(perplexity): expose search_results in chat model (#31468)
Description
The Perplexity chat model already returns a search_results field, but
LangChain dropped it when mapping Perplexity responses to
additional_kwargs.
This patch adds "search_results" to the allowed attribute lists in both
_stream and _generate, so downstream code can access it just like
images, citations, or related_questions.

Dependencies
None. The change is purely internal; no new imports or optional
dependencies required.


https://community.perplexity.ai/t/new-feature-search-results-field-with-richer-metadata/398

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Mason Daugherty <github@mdrxy.com>
2025-07-16 15:16:35 -04:00
..
langchain_perplexity feat(perplexity): expose search_results in chat model (#31468) 2025-07-16 15:16:35 -04:00
scripts
tests feat(perplexity): expose search_results in chat model (#31468) 2025-07-16 15:16:35 -04:00
.gitignore
LICENSE
Makefile fix: automatically fix issues with ruff (#31897) 2025-07-07 14:13:10 -04:00
pyproject.toml ruff: more rules across the board & fixes (#31898) 2025-07-07 17:48:01 -04:00
README.md
uv.lock [Doc] Improve api doc for perplexity (#31636) 2025-06-17 14:10:43 +00:00

langchain-perplexity

This package contains the LangChain integration with Perplexity.

Installation

pip install -U langchain-perplexity

And you should configure your perplexity credentials and then set the PPLX_API_KEY environment variable.

Usage

This package contains the ChatPerplexity class, which is the recommended way to interface with Perplexity chat models.

import getpass
import os

if not os.environ.get("PPLX_API_KEY"):
  os.environ["PPLX_API_KEY"] = getpass.getpass("Enter API key for Perplexity: ")

from langchain.chat_models import init_chat_model

llm = init_chat_model("llama-3.1-sonar-small-128k-online", model_provider="perplexity")
llm.invoke("Hello, world!")