Server Guide
Quguo Limited2024-01-19
Server Guide
Getting Started
The server component of PocketLittle Toy is responsible for processing voice commands and generating responses using AI models. We provide both Docker deployment and manual deployment options.
System Requirements
- CPU: 2 cores or above
- Memory: 4GB minimum, 8GB recommended
- Storage: 20GB minimum
- Operating System: Ubuntu 20.04 or newer
- Docker version 20.10 or newer
Prerequisites
- Docker and Docker Compose installed
- Valid API keys for AI models (OpenAI, DeepSeek, etc.)
- Domain name (optional, for HTTPS)
- Basic knowledge of Linux and Docker
Deployment Files
Directory Structure
server/
├── docker-compose.yml
├── .env
├── config/
│ ├── nginx/
│ │ └── nginx.conf
│ └── app/
│ └── config.yaml
├── data/
│ └── db/
└── logs/
Configuration Files
.env
: Environment variablesOPENAI_API_KEY=your_api_key DEEPSEEK_API_KEY=your_api_key PORT=3000
config.yaml
: Application configurationserver: port: 3000 host: 0.0.0.0 ai: default_model: gpt-3.5-turbo timeout: 30000 max_tokens: 2000 audio: sample_rate: 16000 channels: 1 format: wav
Deployment Methods
Docker Deployment (Recommended)
Clone the repository:
git clone https://github.com/your-repo/pkl-server.git cd pkl-server
Configure environment variables:
cp .env.example .env # Edit .env with your settings
Start the services:
docker-compose up -d
Manual Deployment
Install dependencies:
npm install # or yarn install
Configure the application:
cp config.example.yaml config.yaml # Edit config.yaml
Start the server:
npm run start # or yarn start
Common Issues
Connection Issues
Check if the server is running:
docker-compose ps # or pm2 status
Verify network connectivity:
curl http://localhost:3000/health
API Issues
- Validate API keys in
.env
- Check API quotas and limits
- Review server logs:
docker-compose logs -f app
Performance Issues
Monitor system resources:
docker stats # or htop
Check log files for errors:
tail -f logs/error.log
Maintenance
Backup
Database backup:
docker-compose exec db pg_dump -U postgres > backup.sql
Configuration backup:
tar -czf config-backup.tar.gz config/
Updates
Pull latest changes:
git pull origin main
Update containers:
docker-compose pull docker-compose up -d
Monitoring
- Set up health checks
- Configure log rotation
- Monitor system metrics
- Set up alerts for critical issues
Security
- Keep system updated
- Use HTTPS
- Configure firewall
- Regular security audits
API Documentation
Authentication
POST /api/auth
Content-Type: application/json
{
"device_id": "your_device_id",
"api_key": "your_api_key"
}
Voice Processing
POST /api/voice
Content-Type: multipart/form-data
audio_file: <binary>
Chat Completion
POST /api/chat
Content-Type: application/json
{
"message": "Hello",
"model": "gpt-3.5-turbo"
}
For more detailed API documentation, please visit our API Reference.