mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-31 10:23:18 +00:00
partners: Add Perplexity Chat Integration (#30618)
Perplexity's importance in the space has been growing, so we think it's time to add an official integration! Note: following the release of `langchain-perplexity` to `pypi`, we should be able to add `perplexity` as an extra in `libs/langchain/pyproject.toml`, but we're blocked by a circular import for now. --------- Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com> Co-authored-by: Chester Curme <chester.curme@gmail.com>
This commit is contained in:
29
libs/partners/perplexity/README.md
Normal file
29
libs/partners/perplexity/README.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# langchain-perplexity
|
||||
|
||||
This package contains the LangChain integration with Perplexity.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
pip install -U langchain-perplexity
|
||||
```
|
||||
|
||||
And you should [configure your perplexity credentials](https://docs.perplexity.ai/guides/getting-started)
|
||||
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.
|
||||
|
||||
```python
|
||||
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!")
|
||||
```
|
Reference in New Issue
Block a user