Metadata-Version: 2.4
Name: django-chain
Version: 0.2.0a1
Summary: A Django-based library for seamless LLM integration
Project-URL: homepage, https://github.com/Brian-Kariu/django-chain/
Project-URL: repository, https://github.com/Brian-Kariu/django-chain/
Project-URL: documentation, https://github.com/Brian-Kariu/django-chain/blob/main/README.md
Project-URL: changelog, https://github.com/Brian-Kariu/django-chain/blob/main/CHANGELOG.md
Project-URL: Bug Tracker, https://github.com/Brian-Kariu/django-chain/issues
Author: Brian Kariu
License-Expression: MIT
License-File: LICENSE.txt
Keywords: django,langchain
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.9
Requires-Dist: django>=4.0
Requires-Dist: langchain-community>=0.1.0
Requires-Dist: langchain-core>=0.1.0
Requires-Dist: langchain>=0.1.0
Requires-Dist: psycopg2-binary>=2.9.0
Requires-Dist: python-decouple>=3.8
Provides-Extra: all
Requires-Dist: celery>=5.0; extra == 'all'
Requires-Dist: chromadb>=0.4.0; extra == 'all'
Requires-Dist: django-celery-beat>=2.0; extra == 'all'
Requires-Dist: django-celery-results>=2.0; extra == 'all'
Requires-Dist: langchain-community>=0.1.0; extra == 'all'
Requires-Dist: langchain-google-genai>=0.1.0; extra == 'all'
Requires-Dist: langchain-huggingface>=0.1.0; extra == 'all'
Requires-Dist: langchain-openai>=0.1.0; extra == 'all'
Requires-Dist: langchain-pinecone>=0.1.0; extra == 'all'
Requires-Dist: pgvector>=0.1.0; extra == 'all'
Requires-Dist: sentry-sdk>=1.0; extra == 'all'
Provides-Extra: celery
Requires-Dist: celery>=5.0; extra == 'celery'
Requires-Dist: django-celery-beat>=2.0; extra == 'celery'
Requires-Dist: django-celery-results>=2.0; extra == 'celery'
Provides-Extra: chroma
Requires-Dist: chromadb>=0.4.0; extra == 'chroma'
Requires-Dist: langchain-community>=0.1.0; extra == 'chroma'
Provides-Extra: dev
Requires-Dist: commitizen; extra == 'dev'
Requires-Dist: coverage>=7.0.0; extra == 'dev'
Requires-Dist: factory-boy>=3.3.0; extra == 'dev'
Requires-Dist: faker>=18.0.0; extra == 'dev'
Requires-Dist: model-bakery>=1.20.5; extra == 'dev'
Requires-Dist: mypy>=1.5.1; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
Requires-Dist: pytest-django>=4.5.0; extra == 'dev'
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-gen-files; extra == 'docs'
Requires-Dist: mkdocs-literate-nav; extra == 'docs'
Requires-Dist: mkdocs-material; extra == 'docs'
Requires-Dist: mkdocs-section-index; extra == 'docs'
Requires-Dist: mkdocs==1.6.1; extra == 'docs'
Requires-Dist: mkdocstrings[python]; extra == 'docs'
Provides-Extra: google
Requires-Dist: langchain-google-genai>=0.1.0; extra == 'google'
Provides-Extra: huggingface
Requires-Dist: langchain-huggingface>=0.1.0; extra == 'huggingface'
Provides-Extra: openai
Requires-Dist: langchain-openai>=0.1.0; extra == 'openai'
Provides-Extra: pgvector
Requires-Dist: langchain-community>=0.1.0; extra == 'pgvector'
Requires-Dist: pgvector>=0.1.0; extra == 'pgvector'
Provides-Extra: pinecone
Requires-Dist: langchain-pinecone>=0.1.0; extra == 'pinecone'
Provides-Extra: sentry
Requires-Dist: sentry-sdk>=1.0; extra == 'sentry'
Description-Content-Type: text/markdown

# 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](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2FBrian-Kariu%2Fdjango-chain%2Fmain%2Fpyproject.toml)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
[![codecov](https://codecov.io/gh/Brian-Kariu/django-chain/graph/badge.svg?token=C2C53JBPKO)](https://codecov.io/gh/Brian-Kariu/django-chain)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/Brian-Kariu/django-chain/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![documentation](https://img.shields.io/badge/docs-mkdocs-708FCC.svg?style=flat)](https://mkdocstrings.github.io/)

## 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

```bash
pip install django-chain
```

Add `django_chain` to your `INSTALLED_APPS`:

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

Add you LLM model configurations:

```python
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:
```bash
python manage.py makemigrations django_chain
python manage.py migrate django_chain
```

## Quick Start
Add these urls to your app:
```python
# 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:
   ```bash
   pip install -e ".[dev]"
   ```
3. Install pre-commit hooks:
   ```bash
   pre-commit install
   ```
4. Run tests:
   ```bash
   pytest
   ```

## License

MIT License
