Skip to content

phougt/chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Chatbot Application

A professional, secure AI-powered chatbot web application built with Django and integrated with Groq's free LLM API.

🌟 Features

  • Secure Authentication: User registration and login with password validation
  • AI-Powered Chat: Real-time conversations with advanced language models
  • Session Management: Create and manage multiple conversation sessions
  • Conversation History: All messages are persisted and retrievable
  • User Profile: Track usage statistics and account information
  • Responsive Design: Works seamlessly on desktop, tablet, and mobile devices
  • Input Validation: Comprehensive security measures including CSRF protection
  • Professional UI: Modern, clean interface with Bootstrap 5

πŸ“‹ Requirements

  • Python 3.13 or higher
  • PostgreSQL (optional - SQLite is used by default)
  • Modern web browser
  • Internet connection (for LLM API access)

πŸš€ Installation

1. Clone the Repository

git clone <repository-url>
cd assignment

2. Create Virtual Environment

python -m venv .venv

3. Activate Virtual Environment

Windows:

.venv\Scripts\activate

macOS/Linux:

source .venv/bin/activate

4. Install Dependencies

pip install -r requirements.txt

5. Configure Environment Variables

Create a .env file in the project root:

# Database Configuration
DB_NAME=chatbot_db
DB_USER=postgres
DB_PASSWORD=postgres
DB_HOST=localhost
DB_PORT=5432

# Django Secret Key
SECRET_KEY=your-secret-key-here

# Debug Mode
DEBUG=True

# LLM API Configuration (Using Groq - Free Tier)
LLM_API_KEY=your_groq_api_key_here
LLM_API_URL=https://api.groq.com/openai/v1/chat/completions
LLM_MODEL=llama-3.1-70b-versatile

Get your free Groq API key:

  1. Visit https://console.groq.com/
  2. Sign up for a free account
  3. Generate an API key
  4. Add it to your .env file

6. Run Database Migrations

python manage.py makemigrations
python manage.py migrate

7. Create Superuser (Optional)

python manage.py createsuperuser

8. Run Development Server

python manage.py runserver

Visit http://127.0.0.1:8000/ in your browser.

πŸ“– Usage

Registration

  1. Click "Sign Up" on the login page
  2. Enter username, email, and password
  3. Click "Create Account"

Using the Chatbot

  1. Log in with your credentials
  2. Type your message in the input box
  3. Press Enter or click the send button
  4. Wait for the AI response

Managing Conversations

  • New Conversation: Click the "+" button in the sidebar
  • Switch Conversations: Click on any conversation in the sidebar
  • Delete Conversation: Click the trash icon next to a conversation

πŸ—οΈ Project Structure

assignment/
β”œβ”€β”€ chatbot/                    # Main Django app
β”‚   β”œβ”€β”€ migrations/            # Database migrations
β”‚   β”œβ”€β”€ static/chatbot/        # Static files (CSS, JS)
β”‚   β”œβ”€β”€ templates/chatbot/     # HTML templates
β”‚   β”œβ”€β”€ admin.py               # Admin configuration
β”‚   β”œβ”€β”€ forms.py               # Form definitions with validation
β”‚   β”œβ”€β”€ models.py              # Database models
β”‚   β”œβ”€β”€ views.py               # View functions
β”‚   β”œβ”€β”€ urls.py                # URL routing
β”‚   └── llm_service.py         # LLM API integration
β”œβ”€β”€ chatbot_project/           # Project settings
β”‚   β”œβ”€β”€ settings.py            # Django settings
β”‚   β”œβ”€β”€ urls.py                # Main URL configuration
β”‚   └── wsgi.py                # WSGI configuration
β”œβ”€β”€ Documentation/             # Project documentation (DOCX)
β”‚   β”œβ”€β”€ 1_Project_Proposal.docx
β”‚   β”œβ”€β”€ 2_Software_Requirements_Specification.docx
β”‚   β”œβ”€β”€ 3_Project_Plan.docx
β”‚   β”œβ”€β”€ 4_System_Design_Document.docx
β”‚   β”œβ”€β”€ 5_Test_Plan_and_Summary.docx
β”‚   └── 6_Project_Closing_Report.docx
β”œβ”€β”€ User_Materials/            # User documentation
β”‚   └── User_Manual.docx
β”œβ”€β”€ Process_Artifacts/         # Process documents
β”‚   β”œβ”€β”€ Mid_Project_Status_Reports.docx
β”‚   └── Final_Presentation_Outline.docx
β”œβ”€β”€ manage.py                  # Django management script
β”œβ”€β”€ requirements.txt           # Python dependencies
β”œβ”€β”€ .env                       # Environment variables (create this)
└── README.md                  # This file

πŸ”’ Security Features

  • Password hashing with PBKDF2-SHA256
  • CSRF protection on all forms
  • Session-based authentication
  • Input validation and sanitization
  • SQL injection prevention via Django ORM
  • XSS protection through template auto-escaping
  • Authorization checks on all protected resources

πŸ§ͺ Testing

The application includes comprehensive testing:

  • Authentication tests
  • Chat functionality tests
  • Session management tests
  • Security tests
  • Input validation tests

All test cases are documented in Documentation/5_Test_Plan_and_Summary.docx

πŸ“š Documentation

Complete project documentation is available in the Documentation/ folder:

  1. Project Proposal: Project overview and objectives
  2. SRS: Detailed functional and non-functional requirements
  3. Project Plan: Work breakdown structure and schedule
  4. System Design Document: Architecture and design details
  5. Test Plan and Summary: Testing strategy and results
  6. Project Closing Report: Final project summary

Additional documentation:

  • User Manual: Comprehensive guide for end users
  • Status Reports: Mid-project progress reports
  • Presentation Outline: Final presentation structure

πŸ› οΈ Technology Stack

  • Backend: Django 6.0 (Python 3.13)
  • Database: SQLite (default) / PostgreSQL
  • Frontend: HTML5, CSS3, JavaScript, jQuery
  • UI Framework: Bootstrap 5
  • LLM API: Groq (Free Tier - LLaMA 3.1 70B)
  • Authentication: Django built-in auth system

πŸ”§ Configuration

Using PostgreSQL (Production)

  1. Install PostgreSQL
  2. Create database:
CREATE DATABASE chatbot_db;
  1. Update .env file with PostgreSQL credentials

  2. Update settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': os.getenv('DB_NAME'),
        'USER': os.getenv('DB_USER'),
        'PASSWORD': os.getenv('DB_PASSWORD'),
        'HOST': os.getenv('DB_HOST'),
        'PORT': os.getenv('DB_PORT'),
    }
}

πŸ“Š Admin Panel

Access the Django admin panel at http://127.0.0.1:8000/admin/

Features:

  • User management
  • Conversation monitoring
  • Message history viewing
  • System statistics

πŸ› Troubleshooting

API Key Issues

  • Ensure your Groq API key is correctly set in .env
  • Check API rate limits if responses fail

Database Issues

  • Run python manage.py migrate if you see database errors
  • Delete db.sqlite3 and re-run migrations for a fresh start

Static Files Not Loading

python manage.py collectstatic

πŸ“ License

This is an academic project for educational purposes.

πŸ‘₯ Contributors

[Your Name/Team Name]

πŸ“§ Contact

For questions or support, please contact [your-email@example.com]

🎯 Future Enhancements

  • Voice input/output capabilities
  • Multi-language support
  • Conversation export functionality
  • Mobile applications (iOS/Android)
  • Advanced analytics dashboard
  • Integration with additional LLM providers

⚑ Quick Start Commands

# Setup
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt

# Configure .env file with your API key

# Initialize database
python manage.py migrate

# Run server
python manage.py runserver

# Generate documentation (if needed)
python generate_docs_part1.py
python generate_docs_part2.py
python generate_docs_part3.py

Note: This application uses a free-tier LLM API. For production use, consider upgrading to a paid plan or implementing additional caching mechanisms to manage API rate limits effectively.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published