Skip to content

MIbnEKhalid/ChatAPI

Repository files navigation

🤖 ChatAPI - AI Chat Assistant

A modern, full-featured AI chat application powered by Google Gemini, Groq, Cerebras, and SambaNova. This application provides a unified interface to interact with cutting-edge models like Gemini 2.0 Flash, Llama 3.1, and Gemma 2, complete with user management, conversation history, and an admin dashboard.

Node.js Express.js PostgreSQL License

🌟 Features

🎯 Core Capabilities

  • Multi-Model Support: Seamlessly switch between:
    • Google: Gemini 2.0 Flash, Gemini 1.5 Flash
    • Groq: Llama 3.1 8B (Instant), Gemma 2 9B
    • Cerebras: Llama 3.1 8B (Super Fast)
    • SambaNova: Llama 3.1 8B (Balanced)
  • Efficient Tier Selection: Optimized model selection for speed and reliability.
  • Contextual Memory: Persistent conversation history stored in PostgreSQL.

🎨 User Experience

  • Interactive Gallery: Feature showcase with a built-in Lightbox Image Viewer.
  • Modern UI: Cyberpunk/Glassmorphism inspired design with dark/light theme support.
  • Responsive Design: Fully optimized for Desktop and Mobile devices (including sidebar navigation).
  • Customization: Adjustable font sizes, temperature controls, and theme settings.
  • Rich Text: Markdown support for code blocks, tables, and lists in chat responses.

🔧 Admin & Control

  • Admin Dashboard: Comprehensive panel to manage users and view system stats.
  • User Management: Role-based access control (Admin/User).
  • Message Limits: Configurable daily message quotas per user to manage API costs.
  • Analytics: Monitor chat volume and user activity.

🚀 Quick Start

Prerequisites

  • Node.js 18 or higher
  • PostgreSQL database (Local or Cloud like Neon/Supabase)
  • API Keys for the providers you wish to use (Google, Groq, etc.)

Installation

  1. Clone the repository

    git clone https://github.com/MIbnEKhalid/ChatAPI.git
    cd ChatAPI
  2. Install dependencies

    npm install
  3. Set up environment variables Create a .env file in the root directory:

    cp .env.template .env

    See the Environment Variables section below.

  4. Set up the database Run the SQL script to create the necessary tables:

    psql -U your_username -d your_database -f model/db.sql
  5. Start the application

    npm start
  6. Access the application

    • Main Application: http://localhost:3030
    • Admin Dashboard: http://localhost:3030/admin

🔧 Environment Variables

Configure the following in your example.env.template file: .env.template.

🗄️ Database Schema

The application uses PostgreSQL with the following main tables:

  • ai_history_chatapi: Stores conversation threads, messages, and timestamps.
  • user_message_logs_chatapi: Tracks daily message usage for rate limiting.
  • users (or equivalent): User credentials and role management.

🛠️ Tech Stack

  • Backend: Node.js, Express.js
  • Database: PostgreSQL
  • Frontend: Handlebars (HBS), Vanilla CSS/JS
  • Authentication: Session-based (Custom/Passport)
  • AI Integration: Official SDKs and REST APIs

📱 API Endpoints

Chat Operations

  • GET /chatbot - Render the chat interface.
  • POST /api/chat - Process user message and return AI response.
  • GET /api/history - Fetch conversation history.
  • DELETE /api/chat/:id - Delete a specific conversation.

Admin

  • GET /admin/dashboard - View system statistics.
  • GET /admin/users - Manage registered users.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

👨‍💻 Team

Name Role Links
Muhammad Bin Khalid Lead Developer GitHub Website
Maaz Waheed Developer GitHub

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

For questions or contributions, please contact Muhammad Bin Khalid at mbktech.org/Support, support@mbktech.org , chmuhammadbinkhalid28.com and wwork4287@gmail.com.

About

A chatbot built using Node.js, Handlebars, and PostgreSQL, leveraging the Gemini model and NVIDIA's free API for enhanced functionality.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors