Skip to content

dilancroos/django_chat

Repository files navigation

Contributors Forks Stargazers Issues LinkedIn


Django Local RAG Chat

Université Paris Cité - M2 - Digital Science (AIRE)

Dilan Croos
Explore the docs »

· Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Contact
  4. Acknowledgments

About the Project

A local Django chat app that answers questions from files you place in a local knowledge-base folder. Source files are converted to Markdown with Microsoft's MarkItDown first, then the app indexes only the generated Markdown files. The app uses Ollama for local chat and embedding models, so it does not need a paid LLM API after installation.

(back to top)

Getting Started

To get a local copy up and running follow these simple steps.

Requirements

  • Python 3.11 or newer
  • Ollama running locally

Install Ollama from https://ollama.com/download, then pull the default models:

ollama pull llama3.2
ollama pull nomic-embed-text

Setup

Clone the repo

 git clone git@github.com:dilancroos/django_chat.git
 cd django_chat

Create and activate a virtual environment:

python3 -m venv .venv
source .venv/bin/activate

Install dependencies:

pip install -r requirements.txt

Create an environment file:

cp envtemp .env

Run the database migrations and create a user:

python manage.py migrate
python manage.py makemigrations

again

python manage.py migrate
python manage.py createsuperuser

Knowledge Base

Put source files in knowledge_base/. The app converts them into Markdown in knowledge_markdown/, then indexes only those generated .md files.

Supported first-version source file types are:

  • PDF
  • Word
  • PowerPoint
  • XLS and XLSX
  • CSV
  • Markdown
  • TXT
  • HTML
  • JSON and XML
  • ZIP

The app checks this folder when you send a chat message. If files changed, it converts the files into Markdown, then rebuilds the local index in rag_storage/ before answering.

You can rebuild the index manually:

python manage.py rebuild_rag_index

To skip rebuilding when the stored manifest is current:

python manage.py rebuild_rag_index --skip-unchanged

Run

Start Ollama, then start Django:

python manage.py runserver

Open http://127.0.0.1:8000, sign in, and ask questions about the files in knowledge_base/. Do not edit knowledge_markdown/ manually; it is generated from the source folder.

The app automatically creates the ai-chat chat group and botty bot user the first time a chat message is sent.

Configuration

These settings can be changed in .env:

OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_CHAT_MODEL=llama3.2
OLLAMA_EMBED_MODEL=nomic-embed-text
RAG_SOURCE_DIR=knowledge_base
RAG_MARKDOWN_DIR=knowledge_markdown
RAG_STORAGE_DIR=rag_storage

Tests

python manage.py test

Contact

Dilan Croos - mail@dilancroos.com

Project Link: https://github.com/dilancroos/django_chat

(back to top)

Acknowledgments

(back to top)

About

Llama Api powered chatbot

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors