Metadata-Version: 2.4
Name: langchain-sarvamai
Version: 0.1.0
Summary: An integration package connecting Sarvam AI and LangChain
Project-URL: Homepage, https://www.sarvam.ai
Project-URL: Documentation, https://docs.sarvam.ai
Project-URL: Source, https://github.com/sarvamai/langchain-sarvam
Project-URL: Bug Tracker, https://github.com/sarvamai/langchain-sarvam/issues
Project-URL: Changelog, https://github.com/sarvamai/langchain-sarvam/blob/main/CHANGELOG.md
Author-email: Sarvam AI <devrel@sarvam.ai>
License: MIT
Keywords: ai,indian-languages,langchain,llm,nlp,sarvam
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Typing :: Typed
Requires-Python: <4.0,>=3.10
Requires-Dist: langchain-core<2.0.0,>=0.3.0
Requires-Dist: pydantic<3.0.0,>=2.0.0
Requires-Dist: sarvamai<1.0.0,>=0.1.0
Provides-Extra: lint
Requires-Dist: ruff<1.0.0,>=0.5.0; extra == 'lint'
Provides-Extra: test
Requires-Dist: langchain-tests<1.0.0,>=0.3.0; extra == 'test'
Requires-Dist: pytest-asyncio<1.0.0,>=0.23.0; extra == 'test'
Requires-Dist: pytest-mock<4.0.0,>=3.14.0; extra == 'test'
Requires-Dist: pytest-socket<1.0.0,>=0.7.0; extra == 'test'
Requires-Dist: pytest-watcher<1.0.0,>=0.4.0; extra == 'test'
Requires-Dist: pytest<9.0.0,>=8.0.0; extra == 'test'
Requires-Dist: syrupy<6.0.0,>=4.0.0; extra == 'test'
Provides-Extra: test-integration
Requires-Dist: langchain-tests<1.0.0,>=0.3.0; extra == 'test-integration'
Requires-Dist: pytest-asyncio<1.0.0,>=0.23.0; extra == 'test-integration'
Requires-Dist: pytest<9.0.0,>=8.0.0; extra == 'test-integration'
Requires-Dist: sarvamai<1.0.0,>=0.1.0; extra == 'test-integration'
Provides-Extra: typing
Requires-Dist: mypy<2.0.0,>=1.10.0; extra == 'typing'
Description-Content-Type: text/markdown

# langchain-sarvamai

The `langchain-sarvamai` package provides a LangChain integration for [Sarvam AI](https://www.sarvam.ai)'s language models, optimised for Indian languages and enterprise workloads.

## Installation

```bash
pip install langchain-sarvamai
```

## Setup

Get your API key from [Sarvam AI](https://www.sarvam.ai) and set it as an environment variable:

```bash
export SARVAM_API_KEY="your-api-key"
```

## Usage

### Chat Model

```python
from langchain_sarvamai import ChatSarvam

llm = ChatSarvam(model="sarvam-105b")

# Invoke
response = llm.invoke("What is the capital of India?")
print(response.content)

# With system message
from langchain_core.messages import HumanMessage, SystemMessage

messages = [
    SystemMessage(content="You are a helpful assistant."),
    HumanMessage(content="Tell me about Indian languages."),
]
response = llm.invoke(messages)
print(response.content)

# Stream
for chunk in llm.stream("Count from 1 to 5."):
    print(chunk.content, end="", flush=True)

# Async
import asyncio
response = asyncio.run(llm.ainvoke("Hello!"))
```

### Available Models

| Model | Description |
|-------|-------------|
| `sarvam-105b` | Flagship model — best quality (default) |
| `sarvam-30b` | Faster, lighter model |

### Reasoning Mode

```python
llm = ChatSarvam(model="sarvam-105b", reasoning_effort="high")
response = llm.invoke("Explain the Riemann hypothesis.")
# Access reasoning trace
print(response.additional_kwargs.get("reasoning_content"))
```

Supported values for `reasoning_effort`: `"low"`, `"medium"`, `"high"`.

### Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `model` | `str` | `"sarvam-105b"` | Model name |
| `temperature` | `float` | `None` | Sampling temperature `[0, 1]` |
| `max_tokens` | `int` | `None` | Max tokens to generate |
| `top_p` | `float` | `None` | Nucleus sampling probability |
| `streaming` | `bool` | `False` | Enable streaming |
| `reasoning_effort` | `str` | `None` | Reasoning effort: `"low"`, `"medium"`, `"high"` |
| `api_key` | `str` | env var | Sarvam API key |
| `base_url` | `str` | `"https://api.sarvam.ai/v1"` | Custom API base URL |

## Development

```bash
# Install with dev dependencies
pip install -e ".[test]"

# Run unit tests
pytest tests/unit_tests/ -v

# Run integration tests (requires SARVAM_API_KEY)
pytest tests/integration_tests/ -v
```

## License

MIT
