dash-fastapi-chatbot-llamaindex
Table of contents
Chatbot Application
Welcome to the Chatbot Application project, a complete AI-powered chatbot solution featuring a robust backend and multiple user interfaces. This project demonstrates the seamless integration of machine learning capabilities and user-friendly interfaces, making it an excellent addition to any portfolio.
Overview
This project consists of two main components and interfaces:
-
Backend (
Chatbot
folder):- Handles document indexing, query processing, and integration with the vector store for efficient responses
- Built with Python and includes utilities for handling PDFs, FAQs, and other document formats
- Integrates with OpenAI's ChatGPT for natural conversations
-
User Interfaces:
- RAG-powered FAQ Interface:
- Provides intelligent responses based on your document knowledge base
- Built with Dash, offering responsive design and real-time communication
- ChatGPT Conversation Interface:
- Simple and intuitive chat interface for direct interactions with ChatGPT
- Maintains conversation context for natural dialogue flow
- No RAG integration, perfect for general queries and conversations
- RAG-powered FAQ Interface:
Features
Backend Features
- Document Indexing: Supports processing and indexing of documents (e.g., PDFs)
- FAQ Handling: Efficient FAQ vector store for quick and accurate responses
- API Integration: Serves as the foundation for seamless communication with the frontends
- Modular Design: Configurable settings using
config.py
and.env
files - OpenAI Integration: Direct integration with ChatGPT for natural language processing
Frontend Features
- Dual Interface Options: Choose between RAG-powered FAQ bot or direct ChatGPT interactions
- Interactive UI: Sleek and user-friendly interfaces for both chat modes
- Real-Time Interaction: Facilitates real-time responses using state management tools
- Conversation History: Maintains chat context for more natural interactions
- Error Handling: Alerts users to invalid inputs or backend connection issues
Technologies Used
-
Backend:
- Python 3.12+
- FastAPI for API endpoints
- LlamaIndex for document indexing
- LangChain for AI interactions
- OpenAI's ChatGPT integration
-
Frontend:
- Dash Framework
- HTML/CSS for styling
- REST API integration
- Real-time state management
-
Development Tools:
- PowerShell automation
- Python virtual environments
- Environment variable management
Quick Start (Windows)
The easiest way to get started is using our PowerShell automation script:
-
Clone the repository:
git clone https://github.com/miracle5284/dash-fastapi-chatbot-llamaindex.git cd dash-fastapi-chatbot-llamaindex
-
Run the automation script:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser .\run_chatbot.ps1
The script will automatically:
- Check and install Python 3.12 if needed
- Create and configure a virtual environment
- Install all required dependencies
- Prompt for your OpenAI API key
- Set up environment variables
- Start both the FastAPI server and Dash UI
- Open your browser to the chat interface
To stop the application:
- Press
Ctrl+C
in the terminal running the servers - Both servers (FastAPI and Dash UI) will shut down gracefully
Manual Setup
If you prefer manual setup or are using a different operating system:
-
Install Python 3.12:
- Download Python 3.12 from python.org
- Run the installer and make sure to check "Add Python to PATH"
- Verify installation by running:
python --version
-
Create and activate a virtual environment:
# Create virtual environment python -m venv venv # Activate virtual environment # On Windows: .\venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
- Create a
.env
file with:OPENAI_API_KEY=your_api_key_here OPENAI_MODEL_NAME=gpt-3.5-turbo
- Create a
-
Start the servers:
# Start FastAPI server uvicorn chatbot.server:app --reload # Start Dash UI (in another terminal) python chatbot-ui/dash-chat-ui.py
Usage
-
Access the interfaces:
- For ChatGPT-only interface (no RAG):
http://127.0.0.1:5500
- For RAG-powered FAQ interface:
http://127.0.0.1:8050
- For ChatGPT-only interface (no RAG):
-
Choose your interaction mode:
- Use the FAQ interface (port 8050) for document-based queries
- Use the ChatGPT interface (port 5500) for general conversations
-
Enter your queries and receive intelligent responses
-
To stop the application:
- Press
Ctrl+C
on both terminal running the servers
- Press
Note: The PowerShell automation script (run_chatbot.ps1
) is configured to launch the ChatGPT-only interface by default. To use the RAG-powered FAQ interface, you'll need to run:
python chatbot/dash-ui.py
Folder Structure
chatbot/
├── chatbot/ # Backend code
│ ├── config.py # Configuration settings
│ ├── server.py # Main server script
│ ├── indexing.py # Document indexing utilities
│ ├── schemas.py # Data models
│ ├── utils.py # Helper functions
│ └── documents/ # Input documents (e.g., PDFs)
├── chatbot-ui/ # Frontend code
│ ├── dash-chat-ui.py # ChatGPT interface
│ ├── styles.py # UI styling
│ └── config.py # Frontend configuration
├── run_chatbot.ps1 # Windows automation script
├── .env # Environment variables
├── README.md # Project documentation
└── requirements.txt # Python dependencies
Screenshot
Below is an example of the Chatbot UI in action:
Configuration
The application can be configured through several files:
-
Environment Variables (
.env
file):OPENAI_API_KEY=your_api_key_here OPENAI_MODEL_NAME=gpt-3.5-turbo
-
Server Configuration (
chatbot-ui/config.py
):- Configure server URLs, ports, and debug settings
- Settings for both FastAPI backend and Dash UI
-
System Prompt (
system_prompt.txt
):- Contains the instructions and behavior guidelines for the ChatGPT model
- Customize the model's personality and response style
- Modify the prompt to change how the chatbot interacts with users
Contact
- Email: bluprime91@gmail.com
- GitHub: Miracle Mayowa Adebunmi
Models
There are no models linked
Datasets
There are no datasets linked