Skip to main content

Production Ready LangChain

Project description

LongTrainer Logo

LongTrainer - Production-Ready LangChain

PyPI Version Total Downloads Monthly Downloads Open in Colab


Visit Blog Post

Star Follow @ENDEVSOLS

Official Documentation

Explore the comprehensive LongTrainer Documentation for detailed instructions on installation, features, and API usage.

Installation

Introducing LongTrainer, a sophisticated extension of the LangChain framework designed specifically for managing multiple bots and providing isolated, context-aware chat sessions. Ideal for developers and businesses looking to integrate complex conversational AI into their systems, LongTrainer simplifies the deployment and customization of LLMs.

pip install longtrainer

Installation Instructions for Required Libraries and Tools

1. Linux (Ubuntu/Debian)

To install the required packages on a Linux system (specifically Ubuntu or Debian), you can use the apt package manager. The following command installs several essential libraries and tools:

sudo apt install libmagic-dev poppler-utils tesseract-ocr qpdf libreoffice pandoc

2. macOS

On macOS, you can install these packages using brew, the Homebrew package manager. If you don't have Homebrew installed, you can install it from brew.sh.

brew install libmagic poppler tesseract qpdf libreoffice pandoc

Features 🌟

  • Long Memory: Retains context effectively for extended interactions.
  • Multi-Bot Management: Easily configure and manage multiple bots within a single framework, perfect for scaling across various use cases
  • Isolated Chat Sessions: Each bot operates within its own session, ensuring interactions remain distinct and contextually relevant without overlap.
  • Context-Aware Interactions: Utilize enhanced memory capabilities to maintain context over extended dialogues, significantly improving user experience
  • Scalable Architecture: Designed to scale effortlessly with your needs, whether you're handling hundreds of users or just a few.
  • Enhanced Customization: Tailor the behavior to fit specific needs.
  • Memory Management: Efficient handling of chat histories and contexts.
  • GPT Vision Support: Integration Context Aware GPT-powered visual models.
  • Different Data Formats: Supports various data input formats.
  • VectorStore Management: Advanced management of vector storage for efficient retrieval.

Diverse Use Cases:

  • Enterprise Solutions: Streamline customer interactions, automate responses, and manage multiple departmental bots from a single platform.
  • Educational Platforms: Enhance learning experiences with AI tutors capable of maintaining context throughout sessions.
  • Healthcare Applications: Support patient management with bots that provide consistent, context-aware interactions.

Works for All Langchain Supported LLM and Embeddings

  • ✅ OpenAI (default)
  • ✅ VertexAI
  • ✅ HuggingFace
  • ✅ AWS Bedrock
  • ✅ Groq
  • ✅ TogetherAI

Example

VertexAI LLMs

from longtrainer.trainer import LongTrainer
from langchain_community.llms import VertexAI

llm = VertexAI()

trainer = LongTrainer(mongo_endpoint='mongodb://localhost:27017/', llm=llm)

TogetherAI LLMs

from longtrainer.trainer import LongTrainer
from langchain_community.llms import Together

llm = Together(
    model="togethercomputer/RedPajama-INCITE-7B-Base",
    temperature=0.7,
    max_tokens=128,
    top_k=1,
    # together_api_key="..."
)

trainer = LongTrainer(mongo_endpoint='mongodb://localhost:27017/', llm=llm)

Usage Example 🚀

Here's a quick start guide on how to use LongTrainer:

from longtrainer.trainer import LongTrainer
import os

# Set your OpenAI API key
os.environ["OPENAI_API_KEY"] = "sk-"

# Initialize LongTrainer
trainer = LongTrainer(mongo_endpoint='mongodb://localhost:27017/', encrypt_chats=True)
bot_id = trainer.initialize_bot_id()
print('Bot ID: ', bot_id)

# Add Data
path = 'path/to/your/data'
trainer.add_document_from_path(path, bot_id)

# Initialize Bot
trainer.create_bot(bot_id)

# Start a New Chat
chat_id = trainer.new_chat(bot_id)

# Send a Query and Get a Response
query = 'Your query here'
response = trainer.get_response(query, bot_id, chat_id)
print('Response: ', response)

Here's a guide on how to use Vision Chat:

chat_id = trainer.new_vision_chat(bot_id)

query = 'Your query here'
image_paths = ['nvidia.jpg']
response = trainer.get_vision_response(query, image_paths, str(bot_id), str(vision_id))
print('Response: ', response)

List Chats and Display Chat History:

trainer.list_chats(bot_id)

trainer.get_chat_by_id(chat_id=chat_id)

This project is still under active development. Community feedback and contributions are highly appreciated.

Citation

If you utilize this repository, please consider citing it with:

@misc{longtrainer,
  author = {Endevsols},
  title = {LongTrainer: Production-Ready LangChain},
  year = {2023},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/ENDEVSOLS/Long-Trainer}},
}

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

longtrainer-0.2.9.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

longtrainer-0.2.9-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file longtrainer-0.2.9.tar.gz.

File metadata

  • Download URL: longtrainer-0.2.9.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for longtrainer-0.2.9.tar.gz
Algorithm Hash digest
SHA256 c182a23aec01bc120723f68461a87c4df7f2563d19f50955a524c4283dcf257a
MD5 440c5e5a96826da805a7645a6b2b2b90
BLAKE2b-256 87b6bcaa35b665cf6c1f8ebbd6c2d1dd9ba469714df02589325b0277c02afa52

See more details on using hashes here.

File details

Details for the file longtrainer-0.2.9-py3-none-any.whl.

File metadata

  • Download URL: longtrainer-0.2.9-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for longtrainer-0.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 d188013517507cedb54ab2f81d69fb47dabf00d03ee5cea214f0bfd7f75a3f35
MD5 6a6b655fecac471de1b4344d985708b3
BLAKE2b-256 8e587b6708279152f35e213e85b870000ba3d0c7985cb639ff1247f0edfd0a5e

See more details on using hashes here.

Supported by

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