Content Generation Service - Deployment Guide
Overview
This guide covers deploying the Personalized Content Generation service to production.
Prerequisites
Required
- Python 3.9+
- OpenAI API key
- Redis (for caching)
- PostgreSQL (for storage - optional)
Optional
- Docker & Docker Compose
- Kubernetes cluster
- Prometheus + Grafana (monitoring)
- Load balancer (for scaling)
Installation
1. Install Dependencies
# Clone repository
git clone [repository-url]
cd recoagent
# Install requirements
pip install -r requirements.txt
# Verify quality libraries installed
python -c "import textstat, language_tool_python, detoxify, yake; print('✅ All quality libraries installed')"
2. Configure Environment
# Copy example env file
cp env.example .env
# Edit .env with your configuration
nano .env
Required Environment Variables:
# Core
OPENAI_API_KEY=your-api-key-here
CONTENT_GEN_ENVIRONMENT=production
# Optional
CONTENT_GEN_MAX_CONCURRENT_GENERATIONS=10
CONTENT_GEN_ENABLE_QUALITY_SCORING=true
CONTENT_GEN_ENABLE_RATE_LIMITING=true
Running the Service
Development
# Start development server
uvicorn apps.api.content_generation_api:app --reload --port 8000
# Test health endpoint
curl http://localhost:8000/api/v1/content/health
Production
# Start with gunicorn (production WSGI server)
gunicorn apps.api.content_generation_api:app \
--workers 4 \
--worker-class uvicorn.workers.UvicornWorker \
--bind 0.0.0.0:8000 \
--timeout 60 \
--log-level info
Docker Deployment
Dockerfile
FROM python:3.11-slim
WORKDIR /app
# Install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Download language models
RUN python -c "import spacy; spacy.cli.download('en_core_web_sm')"
# Copy application
COPY . .
# Expose port
EXPOSE 8000
# Run application
CMD ["gunicorn", "apps.api.content_generation_api:app", \
"--workers", "4", \
"--worker-class", "uvicorn.workers.UvicornWorker", \
"--bind", "0.0.0.0:8000"]
Docker Compose
version: '3.8'
services:
content-generation:
build: .
ports:
- "8000:8000"
environment:
- OPENAI_API_KEY=${OPENAI_API_KEY}
- CONTENT_GEN_ENVIRONMENT=production
- REDIS_URL=redis://redis:6379
depends_on:
- redis
restart: always
redis:
image: redis:7-alpine
ports:
- "6379:6379"
restart: always
prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./config/prometheus.yml:/etc/prometheus/prometheus.yml
restart: always
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
restart: always
Monitoring Setup
Prometheus Configuration
# config/prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'content-generation'
static_configs:
- targets: ['content-generation:8000']
Grafana Dashboards
Key Metrics to Monitor:
- Requests per minute
- Generation duration (p50, p95, p99)
- Quality scores (avg by content type)
- Error rate
- Cost per hour
- Token usage
Production Checklist
Pre-Launch
- All tests passing (
pytest tests/
) - Load testing completed
- Configuration reviewed
- API keys secured
- Monitoring configured
- Backup strategy defined
- Incident response plan ready
Launch
- Deploy to staging
- Smoke tests on staging
- Deploy to production
- Health check passes
- Monitoring dashboards active
- Alert rules configured
Post-Launch
- Monitor for 24 hours
- Review error logs
- Check performance metrics
- Validate cost tracking
- User feedback collection