7.8 KiB
AI-Powered Support System
A hybrid AI-powered customer support system that combines OpenAI's GPT-4 for complex queries with local LLM (Ollama) for simple queries. The system includes sentiment analysis, real-time chat, and a knowledge base for efficient customer support.
Features
- Hybrid AI System: Combines OpenAI's GPT-4 for complex queries with local LLM (Ollama) for simple queries
- Intelligent Routing: Automatically routes queries to the appropriate AI model based on complexity
- Sentiment Analysis: Analyzes customer sentiment and escalates to human agents when needed
- Real-time Chat: WebSocket-based real-time communication with typing indicators and read receipts
- Knowledge Base: FAQ system with automatic suggestions based on conversation context
- User Authentication: JWT-based authentication with role-based access control
- Admin Dashboard: Analytics and management interface for administrators
- Conversation History: Search and review past conversations
- Scalable Architecture: Built with Go, PostgreSQL, and Redis for high performance
Technology Stack
Backend
- Go: Programming language
- Gin: Web framework
- PostgreSQL: Primary database
- Redis: Caching and session management
- JWT: Authentication
- GORM: ORM for database operations
- Logrus: Structured logging
- Viper: Configuration management
AI Integration
- OpenAI API: For complex queries
- Ollama: For local LLM integration
- Sentiment Analysis: For analyzing customer sentiment
Frontend (To be implemented)
- React/Vue.js: Frontend framework
- WebSocket: Real-time communication
- Material-UI/Ant Design: UI components
Deployment
- Docker: Containerization
- Docker Compose: Local development
- Kubernetes: Production deployment
- CI/CD: Automated testing and deployment
Project Structure
support/
├── backend/ # Backend Go application
│ ├── cmd/ # Application entry point
│ │ └── main.go # Main application file
│ ├── internal/ # Internal application packages
│ │ ├── ai/ # AI service
│ │ ├── auth/ # Authentication service
│ │ ├── conversation/ # Conversation service
│ │ ├── database/ # Database connection and migrations
│ │ ├── handlers/ # HTTP handlers
│ │ ├── knowledge/ # Knowledge base service
│ │ ├── models/ # Data models
│ │ └── routes/ # Route definitions
│ ├── pkg/ # Public library packages
│ │ ├── config/ # Configuration management
│ │ └── logger/ # Logging utilities
│ ├── go.mod # Go module file
│ ├── go.sum # Go module checksums
│ └── Dockerfile # Docker configuration for backend
├── frontend/ # Frontend React/Vue.js application (to be implemented)
├── docs/ # Documentation
├── deployment/ # Kubernetes deployment configurations (to be implemented)
├── docker-compose.yml # Docker Compose configuration
├── .gitignore # Git ignore file
└── README.md # This file
Getting Started
Prerequisites
- Go 1.21 or higher
- Docker and Docker Compose
- PostgreSQL (if not using Docker)
- Redis (if not using Docker)
- OpenAI API key (for GPT-4 integration)
Installation
-
Clone the repository:
git clone https://github.com/yourusername/support.git cd support
-
Set up environment variables:
cp backend/.env.example backend/.env
Edit the
.env
file with your configuration, including your OpenAI API key. -
Start the services using Docker Compose:
docker-compose up -d
-
Wait for all services to start up. You can check the logs with:
docker-compose logs -f
Development
Backend Development
-
Navigate to the backend directory:
cd backend
-
Install dependencies:
go mod download
-
Run the application:
go run cmd/main.go
The backend API will be available at http://localhost:8080
.
Frontend Development (To be implemented)
-
Navigate to the frontend directory:
cd frontend
-
Install dependencies:
npm install
-
Run the development server:
npm run dev
The frontend will be available at http://localhost:3000
.
API Documentation
Authentication Endpoints
POST /api/v1/public/login
- User loginPOST /api/v1/public/register
- User registration
User Endpoints
GET /api/v1/user/profile
- Get user profilePUT /api/v1/user/profile
- Update user profilePUT /api/v1/user/change-password
- Change password
Admin Endpoints
GET /api/v1/admin/users
- List all usersGET /api/v1/admin/users/:id
- Get user by IDPUT /api/v1/admin/users/:id
- Update userDELETE /api/v1/admin/users/:id
- Delete user
Conversation Endpoints
GET /api/v1/conversations
- List conversationsPOST /api/v1/conversations
- Create new conversationGET /api/v1/conversations/:id
- Get conversation by IDPUT /api/v1/conversations/:id
- Update conversationDELETE /api/v1/conversations/:id
- Delete conversationGET /api/v1/conversations/:id/stats
- Get conversation statistics
Message Endpoints
GET /api/v1/conversations/:id/messages
- Get messages in a conversationPOST /api/v1/conversations/:id/messages
- Send a messagePUT /api/v1/conversations/:id/messages/:messageId
- Update a messageDELETE /api/v1/conversations/:id/messages/:messageId
- Delete a messagePOST /api/v1/conversations/:id/ai
- Send message with AI response
Knowledge Base Endpoints
GET /api/v1/knowledge
- Get knowledge base entriesGET /api/v1/knowledge/search
- Search knowledge baseGET /api/v1/knowledge/categories
- Get knowledge categoriesGET /api/v1/knowledge/tags
- Get knowledge tagsGET /api/v1/knowledge/popular
- Get popular knowledge entriesGET /api/v1/knowledge/recent
- Get recent knowledge entriesGET /api/v1/knowledge/best-match
- Find best match for a queryGET /api/v1/knowledge/stats
- Get knowledge base statisticsGET /api/v1/knowledge/:id
- Get knowledge base entry by IDPOST /api/v1/knowledge/:id/rate
- Rate knowledge base entry
Admin Knowledge Base Endpoints
POST /api/v1/admin/knowledge
- Create knowledge base entryPUT /api/v1/admin/knowledge/:id
- Update knowledge base entryDELETE /api/v1/admin/knowledge/:id
- Delete knowledge base entry
AI Endpoints
POST /api/v1/ai/query
- Query AI servicePOST /api/v1/ai/analyze-complexity
- Analyze complexity of a promptGET /api/v1/ai/models
- Get available AI modelsPOST /api/v1/ai/openai
- Query OpenAI directlyPOST /api/v1/ai/ollama
- Query Ollama directly
Testing
Backend Testing
-
Navigate to the backend directory:
cd backend
-
Run tests:
go test ./...
Frontend Testing (To be implemented)
-
Navigate to the frontend directory:
cd frontend
-
Run tests:
npm test
Deployment
Docker Deployment
-
Build the Docker image:
docker build -t support-backend ./backend
-
Run the container:
docker run -p 8080:8080 support-backend
Docker Compose Deployment
-
Start all services:
docker-compose up -d
-
Stop all services:
docker-compose down
Kubernetes Deployment (To be implemented)
- Apply the Kubernetes configurations:
kubectl apply -f deployment/