Skip to content

Latest commit

 

History

History
300 lines (224 loc) · 6.47 KB

File metadata and controls

300 lines (224 loc) · 6.47 KB
LangChat logo

Ship production-grade AI chatbots in minutes

LangChat is a high-performance Python library designed to bridge the gap between "prototype" and "production." It unifies LLMs, vector databases, and session management into a single, modular interface.

Explore the Docs


Why LangChat?

Most AI frameworks are great for experiments but require massive boilerplate for production. LangChat handles the "hard parts" out of the box so you can focus on building features.

Feature LangChat Other Libraries
Setup Time Minutes Days / Weeks
API Key Rotation Built-in Manual
Chat History Automatic Manual
Vector Search Integrated Separate
Reranking Built-in Manual
Production Ready Yes Depends

Installation

pip install langchat

Quick Start

1 — Set your environment variables

# .env
OPENAI_API_KEY=sk-...
PINECONE_API_KEY=pc-...
SUPABASE_URL=https://yourproject.supabase.co
SUPABASE_KEY=your-key

2 — Build and chat

from langchat import LangChat
from langchat.providers import OpenAI, Pinecone, Supabase

lc = LangChat(
    llm=OpenAI("gpt-4o"),
    vector_db=Pinecone("my-index"),
    db=Supabase(),
)

# Async
response = await lc.chat("What is RAG?", user_id="alice")
print(response.text)           # typed response — no dict["response"] needed

# Sync (no asyncio boilerplate)
response = lc.chat_sync("Hello!", user_id="alice")
print(response.text)

All providers read credentials from the environment automatically. No need to pass keys explicitly unless you want to override them.


Providers

LLM providers

Every LLM provider follows the same pattern: model as the first argument, everything else keyword-only.

from langchat.providers import OpenAI, Anthropic, Gemini, Mistral, Cohere, Ollama

# Reads OPENAI_API_KEY from environment
OpenAI()
OpenAI("gpt-4o")
OpenAI("gpt-4o", temperature=0.2)
OpenAI(api_keys=["sk-1", "sk-2"])   # automatic key rotation

# Reads ANTHROPIC_API_KEY
Anthropic()
Anthropic("claude-opus-4-6")

# Reads GEMINI_API_KEY or GOOGLE_API_KEY
Gemini()
Gemini("gemini-1.5-pro")

# Reads MISTRAL_API_KEY
Mistral()
Mistral("mistral-large-latest")

# Reads COHERE_API_KEY
Cohere()
Cohere("command-r")

# No API key required — connects to a local Ollama server
Ollama()
Ollama("mistral")
Ollama("codellama", base_url="http://gpu-server:11434")

Vector database

from langchat.providers import Pinecone

# Reads PINECONE_API_KEY and OPENAI_API_KEY (for embeddings)
Pinecone("my-index")
Pinecone("my-index", embedding_model="text-embedding-3-small")
Pinecone("my-index", api_key="pc-...", embedding_api_key="sk-...")

History database

from langchat.providers import Supabase

# Reads SUPABASE_URL and SUPABASE_KEY
Supabase()
Supabase(url="https://yourproject.supabase.co", key="your-key")

Typed responses

chat() returns a ChatResponse dataclass — no more result["response"] key lookups.

response = await lc.chat("Summarise the docs", user_id="alice", platform="docs")

response.text           # str   — the answer
response.status         # "success" | "error"
response.response_time  # float — wall-clock seconds
response.timestamp      # str   — ISO-8601
response.user_id        # str
response.platform       # str
response.error          # str | None — set when status == "error"

# Boolean protocol
if response:
    print("OK:", response.text)
else:
    print("Error:", response.error)

# Works directly with print / f-strings
print(response)          # same as print(response.text)
print(f"Answer: {response}")

Document indexing

# Single file
lc.index("docs/guide.pdf")

# Multiple files at once
lc.index(["docs/guide.pdf", "docs/api.pdf", "data/faq.csv"])

# With options
lc.index(
    "docs/guide.pdf",
    chunk_size=500,
    chunk_overlap=50,
    namespace="v2",
    prevent_duplicates=True,   # default — safe to call multiple times
)

Custom prompt

PROMPT = """You are a helpful assistant for {platform}.
Use only the provided context to answer questions.

Context:
{context}

Chat history:
{chat_history}

Question: {question}
Answer:"""

lc = LangChat(
    llm=OpenAI("gpt-4o"),
    vector_db=Pinecone("my-index"),
    db=Supabase(),
    prompt_template=PROMPT,
)

As a FastAPI server

from langchat.api.app import create_app
from langchat.providers import OpenAI, Pinecone, Supabase
import uvicorn

app = create_app(
    llm=OpenAI("gpt-4o"),
    vector_db=Pinecone("my-index"),
    db=Supabase(),
)

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)

Endpoints exposed automatically:

Method Path Description
POST /chat Send a message
GET /health Health check
GET /frontend Serves the built-in UI

Use Cases

Education E-commerce Enterprise
Intelligent tutoring and course Q&A Customer support and product discovery Internal knowledge base search

Roadmap & Contributing

We are building the future of conversational AI infrastructure.


Built with ❤️ by NeuroBrain

GitHubPyPIDocumentation