feat(#33100): Add support for Sarvam AI chat models #33349
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Sarvam AI Chat Model Integration
Description
This PR adds official support for Sarvam AI chat models to LangChain, implementing a first-class integration as requested in issue #31100.
Sarvam AI provides LLMs optimized for Indian languages with strong multilingual capabilities, particularly for Indic and low-resource languages. This integration enables developers to seamlessly use Sarvam models within LangChain chains, agents, and RAG pipelines.
Installation
The package can be installed via pip:
Or with poetry:
For development installation:
Requirements
langchain-core>=0.3.30,<0.4
requests
pydantic>=2.0
Changes
New Package:
langchain-sarvam
Created a new partner package at
libs/partners/sarvam/
with:ChatSarvam
class implementingBaseChatModel
interfaceKey Features
✅ Core Functionality
invoke()
,ainvoke()
stream()
,astream()
batch()
,abatch()
✅ Message Types
✅ Configuration Parameters
model
: Model identifier (default: "sarvam-m")temperature
: Sampling temperature (0.0-2.0)max_tokens
: Maximum response lengthtop_p
: Nucleus sampling parameterfrequency_penalty
: Token frequency penalization (-2.0-2.0)presence_penalty
: Token presence penalization (-2.0-2.0)timeout
: Request timeout in secondsmax_retries
: Maximum retry attempts✅ Developer Experience
SARVAM_API_KEY
)File Structure
Testing
Unit Tests (11 passed, 2 skipped)
Integration Tests
Code Quality
ruff check .
passesruff format .
appliedmypy langchain_sarvam
passesUsage Example
First, install the package:
Then use it in your code:
Documentation
docs/integrations/chat/sarvam.ipynb
Compatibility
requests
,pydantic>=2.0
Migration Guide
For users currently using custom Sarvam wrappers:
Before:
After:
Benefits
Related Issues
Closes #31100
Checklist
langchain-sarvam
ChatSarvam
class with full BaseChatModel interfaceBreaking Changes
None - This is a new integration.
Additional Notes
Screenshots/Examples
Basic Chat:
Hindi Support:
Streaming:
Maintainer Notes
SARVAM_API_KEY
environment variable@pytest.mark.scheduled
for CI/CD schedulingReady for Review ✅
This integration has been tested thoroughly and follows all LangChain standards. It provides a robust, production-ready implementation for Sarvam AI chat models.
Here is MRE
`
import os
import sys
`