# langchain-sarvamcloud

This package contains the LangChain integration for [Sarvam AI](https://www.sarvam.ai) — India's sovereign AI platform with comprehensive support for 22+ Indian languages.

## Features

- **Chat completions** (`ChatSarvam`) — Tool calling, streaming, `reasoning_effort` control
- **Speech-to-Text** (`SarvamSTT`, `SarvamBatchSTT`) — 23 languages, REST + batch async
- **Text-to-Speech** (`SarvamTTS`) — 11 languages, 30+ voices
- **Translation** (`SarvamTranslator`) — 22 languages, style modes, code-mixed output
- **Transliteration** (`SarvamTransliterator`) — Script conversion (Devanagari ↔ Roman)
- **Language Detection** (`SarvamLanguageDetector`) — Identify language and script
- **Document Intelligence** (`SarvamDocumentIntelligence`) — OCR/digitization for PDFs

## Installation

```bash
pip install -U langchain-sarvamcloud
```

## Setup

Get your API subscription key from [dashboard.sarvam.ai](https://dashboard.sarvam.ai) and set:

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

## Usage

### Chat

```python
from langchain_sarvamcloud import ChatSarvam

model = ChatSarvam(model="sarvam-105b", temperature=0.2)
response = model.invoke("हिंदी में मेरा परिचय दो।")
print(response.content)
```

### Translation

```python
from langchain_sarvamcloud import SarvamTranslator

translator = SarvamTranslator(model="sarvam-translate:v1")
result = translator.translate(
    "Hello, how are you?",
    source_language_code="en-IN",
    target_language_code="hi-IN",
    mode="formal",
)
print(result["translated_text"])
```

### Speech-to-Text

```python
from langchain_sarvamcloud import SarvamSTT

stt = SarvamSTT(model="saaras:v3")
with open("audio.wav", "rb") as f:
    result = stt.transcribe(f, language_code="hi-IN")
print(result["transcript"])
```

### Document Intelligence

```python
from langchain_sarvamcloud import SarvamDocumentIntelligence

loader = SarvamDocumentIntelligence(
    file_paths=["document.pdf"],
    language="hi-IN",
    output_format="md",
)
docs = loader.load()
print(docs[0].page_content)
```

## Models

| Model | Context Window | Tool Calling | Notes |
|-------|---------------|-------------|-------|
| `sarvam-105b` | 128K tokens | Yes | Flagship (default) |
| `sarvam-105b-32k` | 32K tokens | Yes | Short-context variant |
| `sarvam-30b` | 32K tokens | Yes | Balanced |
| `sarvam-30b-16k` | 16K tokens | Yes | Short-context variant |
| `sarvam-m` | 8K tokens | No | Legacy 24B |

All chat models are **free** to use (no per-token cost).

## Supported Languages

22+ Indian languages including: Hindi (`hi-IN`), Tamil (`ta-IN`), Telugu (`te-IN`), Bengali (`bn-IN`), Kannada (`kn-IN`), Malayalam (`ml-IN`), Gujarati (`gu-IN`), Marathi (`mr-IN`), Punjabi (`pa-IN`), Odia (`od-IN`), and more.
