An integration package connecting Sarvam AI and LangChain
Project description
langchain-sarvamai
The langchain-sarvamai package provides a LangChain integration for Sarvam AI's language models, optimised for Indian languages and enterprise workloads.
Installation
pip install langchain-sarvamai
Setup
Get your API key from Sarvam AI and set it as an environment variable:
export SARVAM_API_KEY="your-api-key"
Usage
Chat Model
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
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
# 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_sarvamai-0.1.0.tar.gz.
File metadata
- Download URL: langchain_sarvamai-0.1.0.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19e005c3bfeafa5f4e7805ea81a89bc508d682e67a87237cb1e6e22915983970
|
|
| MD5 |
4709c7ac6960d97c3f767442ad08114c
|
|
| BLAKE2b-256 |
e6cec4c9f37688d39a96ed5b040e379ea23054613be183bdbb93edf1a0aad00f
|
Provenance
The following attestation bundles were made for langchain_sarvamai-0.1.0.tar.gz:
Publisher:
release.yml on sarvamai/langchain-sarvam
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_sarvamai-0.1.0.tar.gz -
Subject digest:
19e005c3bfeafa5f4e7805ea81a89bc508d682e67a87237cb1e6e22915983970 - Sigstore transparency entry: 2190457476
- Sigstore integration time:
-
Permalink:
sarvamai/langchain-sarvam@1f0eb78cabe6d02d278b8432d905c52853926f8e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/sarvamai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1f0eb78cabe6d02d278b8432d905c52853926f8e -
Trigger Event:
release
-
Statement type:
File details
Details for the file langchain_sarvamai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_sarvamai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3413b0ae9a5cdbf0279e8d3eaebb039c170d104a71aa9aa6a9997be8abd6b7fc
|
|
| MD5 |
3a07379218141a6995992252e324307a
|
|
| BLAKE2b-256 |
5befcc81609f2d04410a479800f085b2ec62e245178341b7cd98a9b3735c30bb
|
Provenance
The following attestation bundles were made for langchain_sarvamai-0.1.0-py3-none-any.whl:
Publisher:
release.yml on sarvamai/langchain-sarvam
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_sarvamai-0.1.0-py3-none-any.whl -
Subject digest:
3413b0ae9a5cdbf0279e8d3eaebb039c170d104a71aa9aa6a9997be8abd6b7fc - Sigstore transparency entry: 2190457483
- Sigstore integration time:
-
Permalink:
sarvamai/langchain-sarvam@1f0eb78cabe6d02d278b8432d905c52853926f8e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/sarvamai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1f0eb78cabe6d02d278b8432d905c52853926f8e -
Trigger Event:
release
-
Statement type: