Skip to content

The web app lets users register, log in, and chat with a Generative AI chatbot, offering a seamless and interactive experience through natural, engaging conversations.

Notifications You must be signed in to change notification settings

HoudaChairi/Chatbot

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– AI Chatbot Platform

AI Chatbot Django React PostgreSQL Together AI

A full-stack web application featuring a powerful AI chatbot powered by Together AI, with user authentication and a responsive interface built with React and Django.

sign-in

sign-up

chatbot

Features

  • User Authentication System

    • Secure signup and login functionality
    • JWT token-based authentication
    • Password strength validation
  • AI Chatbot

    • Real-time conversation with AI assistant
    • Powered by Together AI
    • Clean, intuitive chat interface
  • Responsive Design

    • Works across desktop and mobile devices
    • Modern React-based UI
    • Smooth user experience

Tech Stack

Backend

  • Django 5.1.6: High-level Python web framework
  • Django REST Framework 3.15.2: Powerful toolkit for building Web APIs
  • djangorestframework-simplejwt 5.4.0: JWT authentication for Django REST Framework
  • together 1.5.5: Official Together AI Python client
  • PostgreSQL: Advanced open-source database system

Frontend

  • React: JavaScript library for building user interfaces
  • HTML5/CSS3: Modern web layout and styling
  • JavaScript (ES6+): Dynamic client-side functionality
  • Fetch API: For making API calls to the backend
  • Node.js/npm: Package management and development server

Project Structure

Backend

backend/
β”œβ”€β”€ backend/           # Main Django project settings
β”œβ”€β”€ users/             # User authentication app
β”‚   β”œβ”€β”€ models.py
β”‚   β”œβ”€β”€ serializers.py
β”‚   β”œβ”€β”€ urls.py
β”‚   └── views.py
└── chatbot/           # Chatbot functionality app
    β”œβ”€β”€ models.py
    β”œβ”€β”€ serializers.py
    β”œβ”€β”€ urls.py
    └── views.py

Frontend

frontend/
β”œβ”€β”€ public/            # Static files
β”œβ”€β”€ src/               # React source files
β”‚   β”œβ”€β”€ components/    # React components
β”‚   β”œβ”€β”€ pages/         # Page components
β”‚   β”œβ”€β”€ services/      # API services
β”‚   β”œβ”€β”€ styles/        # CSS styles
β”‚   β”œβ”€β”€ App.js         # Main React component
β”‚   └── index.js       # React entry point
β”œβ”€β”€ package.json       # NPM dependencies and scripts
└── node_modules/      # Node.js packages

Installation

Prerequisites

  • Python 3.10+
  • Node.js and npm
  • PostgreSQL database
  • Together AI API key

Backend Setup

  1. Clone the repository:

    git clone https://github.com/mel-moun/Chatbot.git
    cd Chatbot
  2. Create and activate a virtual environment:

    python3 -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install Python dependencies:

    pip install -r requirements.txt
  4. Set up PostgreSQL database:

    # Install PostgreSQL if not already installed
    # On Ubuntu/Debian:
    sudo apt update
    sudo apt install postgresql postgresql-contrib
    
    # On macOS with Homebrew:
    brew install postgresql
    
    # Start PostgreSQL service
    # On Ubuntu/Debian:
    sudo service postgresql start
    
    # On macOS:
    brew services start postgresql
  5. Create PostgreSQL database and user:

     -- Create database and user
     CREATE DATABASE test_db;
     CREATE USER test_user WITH PASSWORD 'test_password';
     
     -- Recommended user settings
     ALTER ROLE test_user SET client_encoding TO 'utf8';
     ALTER ROLE test_user SET default_transaction_isolation TO 'read committed';
     ALTER ROLE test_user SET timezone TO 'UTC';
     
     -- Grant privileges
     GRANT ALL PRIVILEGES ON DATABASE test_db TO test_user;
     
     -- Connect to the database
     \c test_db
     
     -- Grant schema and object-level privileges
     ALTER SCHEMA public OWNER TO test_user;
     GRANT ALL ON SCHEMA public TO test_user;
     GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO test_user;
     GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO test_user;
     GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO test_user;
     
     -- Optional extensions
     CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
     CREATE EXTENSION IF NOT EXISTS pg_trgm;
     
     -- Set search path
     ALTER ROLE test_user SET search_path TO public;
     
     -- Exit PostgreSQL
      \q
  6. Configure environment variables:

    1. Go to Together.ai and sign up.

    2. Get your API key from the dashboard.

    3. Create a .env file in the Backend directory with the following content:

      SECRET_KEY=django-insecure-dummyt3stingk3y
      DEBUG=True
      TOGETHER_API_KEY=your-together-api-key-here
      DB_ENGINE=django.db.backends.postgresql
      DB_NAME=test_db
      DB_USER=test_user
      DB_PASSWORD=test_password
      DB_HOST=localhost
      DB_PORT=5432
      

    πŸ’‘ You can use a dummy key like test-dummy-key-1234 to run the project locally without chatbot functionality.
    However, to use the AI features, you need a valid API key from Together.ai.

  7. Run migrations:

    cd Backend
    # Make migrations in correct order
    python3 manage.py makemigrations users
    python3 manage.py makemigrations  # For other apps
     
    # Apply all migrations
    python3 manage.py migrate
    
  8. Start the Django development server:

    python3 manage.py runserver

Frontend Setup

  1. Navigate to the frontend directory:

    cd frontend
  2. Install dependencies:

    npm install
  3. Start the development server:

    npm run dev
  4. The application should automatically open in your default browser or navigate to the URL shown in your terminal (typically http://localhost:5173/)

API Endpoints

Authentication

  • POST /api/users/register/: Register a new user
  • POST /api/users/login/: Login and obtain JWT tokens

Chatbot

  • POST /api/chat/: Send a message to the AI chatbot

Security Features

  • JWT token-based authentication
  • Password strength validation
  • Form input validation
  • CORS protection
  • Protection against common web vulnerabilities

About

The web app lets users register, log in, and chat with a Generative AI chatbot, offering a seamless and interactive experience through natural, engaging conversations.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 29.7%
  • JavaScript 28.7%
  • CSS 26.6%
  • HTML 15.0%