Skip to main content

langchain-sarvam

Overview

Integration details

Class Package Local Serializable JS support Downloads Version
ChatSarvam langchain-sarvam ❌ beta ❌ PyPI - Downloads PyPI - Version

Model features

Tool calling Structured output JSON mode Image input Audio input Video input Token-level streaming Native async Token usage Logprobs
❌ ❌ ❌ ❌ ❌ ❌ ✅ ✅ ✅ ❌

Integration package connecting Sarvam AI chat completions with LangChain.

Installation

with uv inside the package:

uv add langchain-sarvam

Setup

# Set the SARVAM API key
sarvam_Api_key = os.getenv("SARVAM_API_KEY")

Usage

Basic Usage

from langchain_sarvam import ChatSarvam

llm = ChatSarvam(model="sarvam-m", temperature=0.2, max_tokens=128)
resp = llm.invoke([("system", "You are helpful"), ("human", "Hello!")])
print(resp.content)

Batch Processing

from langchain_sarvam import ChatSarvam
from langchain_core.messages import HumanMessage

chat = ChatSarvam(model="sarvam-m")

# Batch processing - use list of message lists
messages = [
    [HumanMessage(content="Tell me a joke")],
    [HumanMessage(content="What's the weather like?")]
]

responses = chat.batch(messages)
for response in responses:
    print(response.content)

Using generate() Method

from langchain_sarvam import ChatSarvam
from langchain_core.messages import HumanMessage

chat = ChatSarvam(model="sarvam-m")

# generate() expects a list of message lists
inputs = [
    [HumanMessage(content="Tell me a joke with emojis only")],
    [HumanMessage(content="What's the weather like?")]
]

result = chat.generate(inputs)
for generation_list in result.generations:
    # generation_list is a list of ChatGeneration objects
    for generation in generation_list:
        print(generation.message.content)

Streaming

for chunk in ChatSarvam(model="sarvam-m", streaming=True).stream("Tell me a joke"):
    print(chunk.text, end="")

Metadata

Release files for langchain-sarvam-nishant 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-sarvam-nishant 0.1.0
File Size Uploaded
langchain_sarvam_nishant-0.1.0.tar.gz 131.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-sarvam-nishant 0.1.0
File Interpreter ABI Platform
langchain_sarvam_nishant-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 142.6 kB

Release files / langchain_sarvam_nishant-0.1.0.tar.gz

Download URL langchain_sarvam_nishant-0.1.0.tar.gz
Size 131.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3c10121d4884484da34ef12152b14e2773c0cce38ed224133db24677f270d2b7
BLAKE2b-256 checksum
How to use checksums
e8967e97327a2993b6c528b2b52d8e21ff77ce931f2ac5cabb57a439891a853b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / langchain_sarvam_nishant-0.1.0-py3-none-any.whl

Download URL langchain_sarvam_nishant-0.1.0-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b930d3d20f0bd8b9b8ee593c4eff6c51639a66a4591e73cf915d79cb60d1031
BLAKE2b-256 checksum
How to use checksums
5c532342421348af10a129727a8915cc2188245926fd8cf73913a91a4fdfa165
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page