Metadata-Version: 2.3
Name: langchain-runpod
Version: 0.1.0
Summary: An integration package connecting RunPod and LangChain
License: MIT
Author: Max Forsey
Author-email: max.forsey@runpod.io
Requires-Python: >=3.9,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: httpx (>=0.27.0,<0.28.0)
Requires-Dist: langchain-core (>=0.3.15,<0.4.0)
Requires-Dist: langchain-tests (>=0.3.14,<0.4.0)
Requires-Dist: pydantic (>=2.10.6,<3.0.0)
Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
Requires-Dist: requests (>=2.32.3,<3.0.0)
Project-URL: Repository, https://github.com/max4c/langchain-runpod
Project-URL: Release Notes, https://github.com/maxforsey/langchain-runpod/releases
Project-URL: Source Code, https://github.com/maxforsey/langchain-runpod
Description-Content-Type: text/markdown

# langchain-runpod

This package contains the LangChain integration with [RunPod](https://www.runpod.io).

## Installation

```bash
pip install -U langchain-runpod
```

## Authentication

Configure credentials by setting the following environment variable:

```bash
export RUNPOD_API_KEY="your-runpod-api-key"
```

You can obtain your RunPod API key from the [RunPod API Keys page](https://www.runpod.io/console/user/settings) in your account settings.

## Chat Models

`ChatRunPod` class allows you to interact with any text-based LLM running on RunPod's serverless endpoints.

```python
from langchain_runpod import ChatRunPod

# Create the chat model instance
# Replace "endpoint-id" with your RunPod endpoint ID
chat = ChatRunPod(
    endpoint_id="endpoint-id",  # Your RunPod serverless endpoint ID
    model_name="llama3-70b-chat",  # Optional - for identification purposes
    temperature=0.7,
    max_tokens=1024,
    # api_key="your-runpod-api-key",  # Optional if set as environment variable
)

# Standard invoke method
response = chat.invoke("Tell me fun things to do in NYC")
print(response.content)

# With streaming
for chunk in chat.stream("Tell me fun things to do in NYC"):
    print(chunk.content, end="", flush=True)

# Using multiple messages for chat
from langchain_core.messages import HumanMessage, SystemMessage

messages = [
    SystemMessage(content="You are a helpful travel assistant."),
    HumanMessage(content="What are the must-see attractions in Paris?")
]

response = chat.invoke(messages)
print(response.content)
```

### Important Notes

1. **Endpoint Configuration**: The RunPod endpoint must be running an LLM server that accepts requests in a standard format. Common frameworks like [FastChat](https://github.com/lm-sys/FastChat), [text-generation-webui](https://github.com/oobabooga/text-generation-webui), and [vLLM](https://github.com/vllm-project/vllm) all work.

2. **Response Format**: The integration attempts to handle various response formats from different LLM serving frameworks. If you encounter issues with the response parsing, you may need to customize the `_process_response` method.

3. **Multi-Modal Content**: Currently, multi-modal inputs (images, audio, etc.) are converted to text-only format, as most RunPod endpoints don't support multi-modal inputs.

## Setting Up a RunPod Endpoint

1. Go to [RunPod Serverless](https://www.runpod.io/console/serverless) in your RunPod console
2. Click "New Endpoint"
3. Select a GPU and template (e.g., choose a template that runs vLLM, FastChat, or text-generation-webui)
4. Configure settings and deploy
5. Note the endpoint ID for use with this library

## LLMs

`RunPodLLM` class exposes LLMs from RunPod.

```python
from langchain_runpod import RunPodLLM

llm = RunPodLLM(endpoint_id="endpoint-id")
llm.invoke("The meaning of life is")
```

## Embeddings

`RunPodEmbeddings` class exposes embeddings from RunPod.

```python
from langchain_runpod import RunPodEmbeddings

embeddings = RunPodEmbeddings(endpoint_id="endpoint-id")
embeddings.embed_query("What is the meaning of life?")
```

