Skip to main content

An integration package connecting Sarvam AI and LangChain.

Project description

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="")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_sarvam_nishant-0.1.0.tar.gz (131.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_sarvam_nishant-0.1.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file langchain_sarvam_nishant-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_sarvam_nishant-0.1.0.tar.gz
  • Upload date:
  • Size: 131.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for langchain_sarvam_nishant-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3c10121d4884484da34ef12152b14e2773c0cce38ed224133db24677f270d2b7
MD5 903f2ad31eefd35108251ba5aefaccf8
BLAKE2b-256 e8967e97327a2993b6c528b2b52d8e21ff77ce931f2ac5cabb57a439891a853b

See more details on using hashes here.

File details

Details for the file langchain_sarvam_nishant-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_sarvam_nishant-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b930d3d20f0bd8b9b8ee593c4eff6c51639a66a4591e73cf915d79cb60d1031
MD5 f9d6496aa1db5d025f9f79c4300ae234
BLAKE2b-256 5c532342421348af10a129727a8915cc2188245926fd8cf73913a91a4fdfa165

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page