-
Notifications
You must be signed in to change notification settings - Fork 19.4k
feat(#33100): Add support for Sarvam AI chat models #33349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(#33100): Add support for Sarvam AI chat models #33349
Conversation
- Implement SarvamChat class following BaseChatModel interface - Support configuration via API key and parameters (temperature, max tokens) - Add unit tests and documentation - Fixes langchain-ai#33100 Signed-off-by: shashankyadahalli <[email protected]>
…_Model_Integration
- Implement SarvamChat class following BaseChatModel interface - Support configuration via API key and parameters (temperature, max tokens) - Add unit tests and documentation - Fixes langchain-ai#33100 Signed-off-by: shashankyadahalli <[email protected]>
…ation' of https://github.com/its-shashankY/langchain into fix-langchain-ai#31100-Support_Sarvam_Chat_Model_Integration
- Implement SarvamChat class following BaseChatModel interface - Support configuration via API key and parameters (temperature, max tokens) - Add unit tests and documentation - Fixes langchain-ai#33100 Signed-off-by: shashankyadahalli <[email protected]>
…_Model_Integration
…31100-Support_Sarvam_Chat_Model_Integration
…ation' of https://github.com/its-shashankY/langchain into fix-langchain-ai#31100-Support_Sarvam_Chat_Model_Integration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, thanks for this. This adds a net-new integration into the langchain monorepo. We are recommending that new contributions be implemented via packages in separate repos you control. We've written a walkthrough on this process here:
https://docs.langchain.com/oss/python/contributing/integrations-langchain
We are encouraging contributors of LangChain integrations to go this route. This way we don't have to be in the loop for reviews, you're able to properly integration test the model, and you have control over versioning.
Docs would continue to be maintained centrally in the langchain docs repo.
Let me know what you think!
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
`