Skip to content

avais88k/AI-CSC

Repository files navigation

AI Customer Support Chatbot

A Python chatbot using OpenAI GPT-4o-mini with Saleor GraphQL and MongoDB integration.

Setup

  1. Install dependencies:
pip install -r requirements.txt
  1. Configure environment variables in .env:
  • Add your OpenAI API key
  • Configure Saleor GraphQL endpoint and API token
  • Add MongoDB connection string (for chat storage)
  • Add Langfuse keys for monitoring
  1. Ensure your Saleor instance has proper API access configured

Usage

Command Line:

python main.py

Web API:

python app.py

Backend Components

Core Python Files

  • main.py - Command-line interface for the chatbot
  • app.py - Flask web API server with CORS support and input sanitization
  • chatbot.py - Main chatbot logic with OpenAI GPT-4o-mini integration and Langfuse monitoring
  • database.py - Database abstraction layer handling Saleor GraphQL and MongoDB connections

Configuration Files

  • .env - Environment variables (API keys, database credentials)
  • .env.example - Template for environment configuration
  • requirements.txt - Python dependencies (OpenAI, Flask, PostgreSQL, MongoDB, etc.)
  • gunicorn.conf.py - Gunicorn WSGI server configuration
  • ecosystem.config.js - PM2 process manager configuration

Frontend Components

Next.js Application (/frontend)

  • app/ - Next.js 16 app directory structure
  • components/ - React components including main chatbot interface
  • hooks/ - Custom React hooks for mobile detection and toast notifications
  • lib/ - Utility functions
  • public/ - Static assets

Frontend Technologies

  • Next.js 16 with React 19
  • TypeScript for type safety
  • Tailwind CSS for styling
  • Radix UI components

Database Architecture

Saleor GraphQL

  • Integrates with Saleor e-commerce platform via GraphQL API
  • Fetches order information and product categories
  • Uses API tokens for authentication

MongoDB

  • Stores chat conversation history
  • Uses unique UUIDs for session management

Key Features

  1. Anonymous Chat Sessions - No authentication required
  2. Persistent Chat History - MongoDB with UUID sessions
  3. AI Integration - OpenAI GPT-4o-mini with custom prompts
  4. Order Lookup - Function calling to retrieve order information
  5. Product Categories - AI can fetch available product categories
  6. Observability - Langfuse monitoring and analytics
  7. Security - Input sanitization and request size limits
  8. Modern Frontend - React 19 with TypeScript and Tailwind
  9. Production Ready - Gunicorn + PM2 deployment setup

API Endpoints

  • POST /chat/init - Initialize chat session
  • POST /chat - Main chat endpoint
  • GET /health - Health check endpoint

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published