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.
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
- Python 3.8+
- 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
- Clone the repository
- Install development dependencies:
pip install -e ".[dev]"
- Install pre-commit hooks:
pre-commit install - Run tests:
pytest
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_chain-0.2.0a1.tar.gz.
File metadata
- Download URL: django_chain-0.2.0a1.tar.gz
- Upload date:
- Size: 49.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a435da2ebc7636ad3c4c2ce6cd30884c935f279272b4ba2f2f702f26c58d8d9
|
|
| MD5 |
9785ec0e10fc41219828995a3e193cba
|
|
| BLAKE2b-256 |
adafdc4a3eec1fcb9cda6c5a866862376d056f7920fa7786b33df9904064facc
|
Provenance
The following attestation bundles were made for django_chain-0.2.0a1.tar.gz:
Publisher:
publish.yml on Brian-Kariu/django-chain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_chain-0.2.0a1.tar.gz -
Subject digest:
9a435da2ebc7636ad3c4c2ce6cd30884c935f279272b4ba2f2f702f26c58d8d9 - Sigstore transparency entry: 252094234
- Sigstore integration time:
-
Permalink:
Brian-Kariu/django-chain@845dc42d34b2071ed72028e03c028526e23a6ef4 -
Branch / Tag:
refs/tags/0.2.0a1 - Owner: https://github.com/Brian-Kariu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@845dc42d34b2071ed72028e03c028526e23a6ef4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_chain-0.2.0a1-py3-none-any.whl.
File metadata
- Download URL: django_chain-0.2.0a1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9239f8c63acf67edd606ff68b5a49c05416ac31f74bebe9dc8ed103b0aade74
|
|
| MD5 |
63f5ba50877586050548008990315d16
|
|
| BLAKE2b-256 |
96f6adf35085e4524e8b773af5aaeb35383103372d29f0cc5c93e634546e9011
|
Provenance
The following attestation bundles were made for django_chain-0.2.0a1-py3-none-any.whl:
Publisher:
publish.yml on Brian-Kariu/django-chain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_chain-0.2.0a1-py3-none-any.whl -
Subject digest:
d9239f8c63acf67edd606ff68b5a49c05416ac31f74bebe9dc8ed103b0aade74 - Sigstore transparency entry: 252094238
- Sigstore integration time:
-
Permalink:
Brian-Kariu/django-chain@845dc42d34b2071ed72028e03c028526e23a6ef4 -
Branch / Tag:
refs/tags/0.2.0a1 - Owner: https://github.com/Brian-Kariu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@845dc42d34b2071ed72028e03c028526e23a6ef4 -
Trigger Event:
push
-
Statement type: