This project is a document-aware AI chatbot with memory, document retrieval, and real-time streaming. It's built with Django, PostgreSQL, and LangGraph.
The chatbot allows users to upload .txt documents, which are then used as a knowledge base for the AI. The AI can answer questions about the documents, and it remembers the context of the conversation. The response from the AI is streamed in real-time.
- Document Upload: Upload
.txtfiles to be used as a knowledge base. - Chat with Memory: The chatbot remembers the context of the conversation.
- Document Retrieval: The chatbot can retrieve relevant information from the uploaded documents to answer questions.
- Real-time Streaming: The AI's response is streamed in real-time.
Before you begin, ensure you have the following software installed on your system:
- Git: Download and install from git-scm.com.
- Python 3.8+: Download and install from python.org.
- PostgreSQL: Download and install from postgresql.org.
- VS Code: Download and install from code.visualstudio.com.
-
Clone the repository:
git clone https://github.com/dangeamro/qtec-ai-chatbot.git
-
Create a virtual environment and activate it:
Windows:
python -m venv venv venv\Scripts\activate
Linux/macOS:
python3 -m venv venv source venv/bin/activate -
Install the dependencies:
pip install -r requirements.txt
-
Create a PostgreSQL Database: Ensure you have a PostgreSQL server running. Create a new database for this project (e.g.,
qtec_chatbot_db). -
Create a
.envfile and configure your database connection andGOOGLE_API_KEY: Create a file named.envin the project root with the following content, replacing placeholders with your actual database credentials and API key:DATABASE_URL=postgres://USER:PASSWORD@HOST:PORT/NAME GOOGLE_API_KEY=<your-api-key>Example
DATABASE_URLfor a local PostgreSQL setup:postgres://myuser:mypassword@localhost:5432/qtec_chatbot_db -
Run the database migrations:
python manage.py migrate
-
Create an Admin User (Superuser): Run the following command to create an administrator account for the Django admin panel. Follow the prompts to set up your username, email, and password.
python manage.py createsuperuser
You can access the Django admin panel at
http://127.0.0.1:8000/admin/after starting the development server. -
Run the development server:
python manage.py runserver
Access the chat interface by navigating to http://127.0.0.1:8000/ in your web browser after starting the development server. Type your message in the input field and press "Send" or Enter to interact with the chatbot.
- Endpoint:
POST /api/document/ - Method:
POST - Body:
multipart/form-datawith afilefield containing the.txtfile.
- Endpoint:
POST /api/chat/ - Method:
POST - Body:
{"session_id": <session-id (optional)>, "message": "Your message here"}
- Endpoint:
GET /api/session/<id>/messages/ - Method:
GET