Skip to main content

An integration package connecting Baseten and LangChain

Project description

langchain-baseten

This package contains the LangChain integration with Baseten.

Installation

pip install langchain-baseten

The embeddings functionality uses Baseten's Performance Client for optimized performance:

pip install baseten-performance-client

Chat Models

ChatBaseten class exposes chat models from Baseten.

from langchain_baseten import ChatBaseten

# Option 1: Use Model APIs with model slug (recommended)
chat = ChatBaseten(
    model="deepseek-ai/DeepSeek-V3-0324",  # Choose from available model slugs
    api_key="your-api-key",  # Or set BASETEN_API_KEY env var
)

# Option 2: Use dedicated model URL for deployed models
chat = ChatBaseten(
    model_url="https://model-<id>.api.baseten.co/environments/production/predict",
    api_key="your-api-key",
    # `model` parameter is optional for most dedicated models, but may required for specific models like "openai/gpt-oss-20b", please check APIs endpoint example for your deployment for guidance.
)

# Use the chat model
response = chat.invoke("Hello, how are you?")
print(response.content)

Embeddings

BasetenEmbeddings class exposes embedding models from Baseten.

from langchain_baseten import BasetenEmbeddings

# Initialize the embeddings model
embeddings = BasetenEmbeddings(
    model_url="https://model-<id>.api.baseten.co/environments/production/sync",  # Your model URL
    api_key="your-api-key",  # Or set BASETEN_API_KEY env var
    # model parameter is optional since model_url identifies the model
)

# Embed documents
vectors = embeddings.embed_documents(["Hello world", "How are you?"])
print(f"Generated {len(vectors)} embeddings of dimension {len(vectors[0])}")

# Embed a single query
query_vector = embeddings.embed_query("What is the meaning of life?")
print(f"Query embedding dimension: {len(query_vector)}")

Configuration

You can configure the Baseten integration using environment variables:

  • BASETEN_API_KEY: Your Baseten API key

Deployment Options

Chat Models:

  • Model APIs (recommended): Use model slugs with shared infrastructure
  • Dedicated URLs: Use specific model deployments with dedicated resources

Embeddings:

  • Dedicated URLs only: Requires specific model deployment URL for Performance Client optimization

Supported Models

Baseten supports various models through their OpenAI-compatible API. You can use any model slug available in your Baseten account, or deploy custom models with dedicated URLs.

For more information about available models, visit the Baseten documentation.

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_baseten-0.1.1.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

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

langchain_baseten-0.1.1-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file langchain_baseten-0.1.1.tar.gz.

File metadata

  • Download URL: langchain_baseten-0.1.1.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for langchain_baseten-0.1.1.tar.gz
Algorithm Hash digest
SHA256 58b7088451383550b1e8a088c7eb36be6db4f90aff2a1b1d64b4cfeb31958b19
MD5 086b182d516511e15e12379bee1e046e
BLAKE2b-256 6b848f1b92c299381575eac5352465e153d34c6cb0e15e3dd978b259d7fdd3f7

See more details on using hashes here.

File details

Details for the file langchain_baseten-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_baseten-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0418b6202093dc04173480fb88aa712c5052cdd97f1c35a6138d7b101d6cb36f
MD5 b2611c43c5f420396fa440e901d426e7
BLAKE2b-256 345fec6bfe91b4719becd177874d5abdcb969b90fffde5b1e689f3dea23fab97

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