Skip to main content

A Django-based library for seamless LLM integration

Project description

Django Chain

A Django library for seamless LangChain integration, making it easy to add LLM capabilities to your Django applications. This is a reusable Django application that provides a robust framework for defining, managing, and executing multi-step Large Language Model (LLM) workflows. It offers a set of API endpoints to interact with prompts, workflows, and their execution, enabling dynamic LLM applications without direct code changes for each new workflow.

Python pre-commit codecov GitHub Actions Workflow Status License: MIT Ruff documentation

Features

  • Dynamic prompt and workflow management out of the box
  • Easy integration with existing Django models and views
  • Built-in utilities for common LLM tasks
  • Type-safe and well-documented API
  • Comprehensive test coverage
  • Production-ready with proper error handling

Core Concepts

  • Prompt: Represents a configurable template for generating LLM prompts. This can be a HumanMessagePromptTemplate, SystemMessagePromptTemplate, or ChatPromptTemplate.
  • Workflow: A sequence of ordered steps, each defining an action to be performed (e.g., format a prompt, call an LLM, parse JSON output, use a tool). Workflows orchestrate the flow of data through these steps.

Prerequisites

  1. Python 3.8+
  2. Django 4.0+

Installation

pip install django-chain

Add django_chain to your INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    'django_chain',
    ...
]

Add you LLM model configurations:

DJANGO_LLM_SETTINGS = {
    "DEFAULT_LLM_PROVIDER": "fake",
    "DEFAULT_CHAT_MODEL": {
        "name": "fake-model",
        "temperature": 0.7,
        "max_tokens": 1024,
        "api_key": "fake key",
    },
    "DEFAULT_EMBEDDING_MODEL": {
        "provider": "fake",
        "name": "fake-embedding",
    },
    "VECTOR_STORE": {
        "TYPE": "pgvector",
        "PGVECTOR_COLLECTION_NAME": "test_documents",
    },
    "ENABLE_LLM_LOGGING": True,
    "LLM_LOGGING_LEVEL": "DEBUG",
    "MEMORY": {
        "DEFAULT_TYPE": "buffer",
        "WINDOW_SIZE": 5,
    },
    "CHAIN": {
        "DEFAULT_OUTPUT_PARSER": "str",
        "ENABLE_MEMORY": True,
    },
    "CACHE_LLM_RESPONSES": True,
    "CACHE_TTL_SECONDS": 3600,
}

Run migrations:

python manage.py makemigrations django_chain
python manage.py migrate django_chain

Quick Start

Add these urls to your app:

# your_project/urls.py
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('api/', include('django_chain.urls')), # Or your chosen app name
]

Development

  1. Clone the repository
  2. Install development dependencies:
    pip install -e ".[dev]"
    
  3. Install pre-commit hooks:
    pre-commit install
    
  4. Run tests:
    pytest
    

License

MIT License

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

django_chain-0.2.0a2.tar.gz (49.1 kB view details)

Uploaded Source

Built Distribution

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

django_chain-0.2.0a2-py3-none-any.whl (36.1 kB view details)

Uploaded Python 3

File details

Details for the file django_chain-0.2.0a2.tar.gz.

File metadata

  • Download URL: django_chain-0.2.0a2.tar.gz
  • Upload date:
  • Size: 49.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for django_chain-0.2.0a2.tar.gz
Algorithm Hash digest
SHA256 e3de7f92e6df705b4ef7671bc405b2167adc586147c5da10e1717f376f82ca3a
MD5 d3ba1e31033db6b5d25845d87686ef58
BLAKE2b-256 68dc354d049575f5765a368a04b985b248792c75db8fc1d881277895ab80eb25

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_chain-0.2.0a2.tar.gz:

Publisher: publish.yml on Brian-Kariu/django-chain

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_chain-0.2.0a2-py3-none-any.whl.

File metadata

  • Download URL: django_chain-0.2.0a2-py3-none-any.whl
  • Upload date:
  • Size: 36.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for django_chain-0.2.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 c94ad4956b15e4d2ff7766bb19e0bf9a876cf93f09603598b1fbeeb587c07b5f
MD5 e68dbd334b56dd566e054df974e3144a
BLAKE2b-256 c0bb95308182cc1857a86ce16448108ffe3743c1925f31381ad50689b4fe66e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_chain-0.2.0a2-py3-none-any.whl:

Publisher: publish.yml on Brian-Kariu/django-chain

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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