271 lines
7.8 KiB
Markdown
271 lines
7.8 KiB
Markdown
# 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
|
|
|
|
1. Clone the repository:
|
|
```bash
|
|
git clone https://github.com/yourusername/support.git
|
|
cd support
|
|
```
|
|
|
|
2. Set up environment variables:
|
|
```bash
|
|
cp backend/.env.example backend/.env
|
|
```
|
|
Edit the `.env` file with your configuration, including your OpenAI API key.
|
|
|
|
3. Start the services using Docker Compose:
|
|
```bash
|
|
docker-compose up -d
|
|
```
|
|
|
|
4. Wait for all services to start up. You can check the logs with:
|
|
```bash
|
|
docker-compose logs -f
|
|
```
|
|
|
|
### Development
|
|
|
|
#### Backend Development
|
|
|
|
1. Navigate to the backend directory:
|
|
```bash
|
|
cd backend
|
|
```
|
|
|
|
2. Install dependencies:
|
|
```bash
|
|
go mod download
|
|
```
|
|
|
|
3. Run the application:
|
|
```bash
|
|
go run cmd/main.go
|
|
```
|
|
|
|
The backend API will be available at `http://localhost:8080`.
|
|
|
|
#### Frontend Development (To be implemented)
|
|
|
|
1. Navigate to the frontend directory:
|
|
```bash
|
|
cd frontend
|
|
```
|
|
|
|
2. Install dependencies:
|
|
```bash
|
|
npm install
|
|
```
|
|
|
|
3. Run the development server:
|
|
```bash
|
|
npm run dev
|
|
```
|
|
|
|
The frontend will be available at `http://localhost:3000`.
|
|
|
|
## API Documentation
|
|
|
|
### Authentication Endpoints
|
|
|
|
- `POST /api/v1/public/login` - User login
|
|
- `POST /api/v1/public/register` - User registration
|
|
|
|
### User Endpoints
|
|
|
|
- `GET /api/v1/user/profile` - Get user profile
|
|
- `PUT /api/v1/user/profile` - Update user profile
|
|
- `PUT /api/v1/user/change-password` - Change password
|
|
|
|
### Admin Endpoints
|
|
|
|
- `GET /api/v1/admin/users` - List all users
|
|
- `GET /api/v1/admin/users/:id` - Get user by ID
|
|
- `PUT /api/v1/admin/users/:id` - Update user
|
|
- `DELETE /api/v1/admin/users/:id` - Delete user
|
|
|
|
### Conversation Endpoints
|
|
|
|
- `GET /api/v1/conversations` - List conversations
|
|
- `POST /api/v1/conversations` - Create new conversation
|
|
- `GET /api/v1/conversations/:id` - Get conversation by ID
|
|
- `PUT /api/v1/conversations/:id` - Update conversation
|
|
- `DELETE /api/v1/conversations/:id` - Delete conversation
|
|
- `GET /api/v1/conversations/:id/stats` - Get conversation statistics
|
|
|
|
### Message Endpoints
|
|
|
|
- `GET /api/v1/conversations/:id/messages` - Get messages in a conversation
|
|
- `POST /api/v1/conversations/:id/messages` - Send a message
|
|
- `PUT /api/v1/conversations/:id/messages/:messageId` - Update a message
|
|
- `DELETE /api/v1/conversations/:id/messages/:messageId` - Delete a message
|
|
- `POST /api/v1/conversations/:id/ai` - Send message with AI response
|
|
|
|
### Knowledge Base Endpoints
|
|
|
|
- `GET /api/v1/knowledge` - Get knowledge base entries
|
|
- `GET /api/v1/knowledge/search` - Search knowledge base
|
|
- `GET /api/v1/knowledge/categories` - Get knowledge categories
|
|
- `GET /api/v1/knowledge/tags` - Get knowledge tags
|
|
- `GET /api/v1/knowledge/popular` - Get popular knowledge entries
|
|
- `GET /api/v1/knowledge/recent` - Get recent knowledge entries
|
|
- `GET /api/v1/knowledge/best-match` - Find best match for a query
|
|
- `GET /api/v1/knowledge/stats` - Get knowledge base statistics
|
|
- `GET /api/v1/knowledge/:id` - Get knowledge base entry by ID
|
|
- `POST /api/v1/knowledge/:id/rate` - Rate knowledge base entry
|
|
|
|
#### Admin Knowledge Base Endpoints
|
|
|
|
- `POST /api/v1/admin/knowledge` - Create knowledge base entry
|
|
- `PUT /api/v1/admin/knowledge/:id` - Update knowledge base entry
|
|
- `DELETE /api/v1/admin/knowledge/:id` - Delete knowledge base entry
|
|
|
|
### AI Endpoints
|
|
|
|
- `POST /api/v1/ai/query` - Query AI service
|
|
- `POST /api/v1/ai/analyze-complexity` - Analyze complexity of a prompt
|
|
- `GET /api/v1/ai/models` - Get available AI models
|
|
- `POST /api/v1/ai/openai` - Query OpenAI directly
|
|
- `POST /api/v1/ai/ollama` - Query Ollama directly
|
|
|
|
## Testing
|
|
|
|
### Backend Testing
|
|
|
|
1. Navigate to the backend directory:
|
|
```bash
|
|
cd backend
|
|
```
|
|
|
|
2. Run tests:
|
|
```bash
|
|
go test ./...
|
|
```
|
|
|
|
### Frontend Testing (To be implemented)
|
|
|
|
1. Navigate to the frontend directory:
|
|
```bash
|
|
cd frontend
|
|
```
|
|
|
|
2. Run tests:
|
|
```bash
|
|
npm test
|
|
```
|
|
|
|
## Deployment
|
|
|
|
### Docker Deployment
|
|
|
|
1. Build the Docker image:
|
|
```bash
|
|
docker build -t support-backend ./backend
|
|
```
|
|
|
|
2. Run the container:
|
|
```bash
|
|
docker run -p 8080:8080 support-backend
|
|
```
|
|
|
|
### Docker Compose Deployment
|
|
|
|
1. Start all services:
|
|
```bash
|
|
docker-compose up -d
|
|
```
|
|
|
|
2. Stop all services:
|
|
```bash
|
|
docker-compose down
|
|
```
|
|
|
|
### Kubernetes Deployment (To be implemented)
|
|
|
|
1. Apply the Kubernetes configurations:
|
|
```bash
|
|
kubectl apply -f deployment/
|
|
```
|