✅ Fully functional FastAPI server with comprehensive features: 🏗️ Architecture: - Complete API design documentation - Modular structure (models, auth, service, main) - OpenAPI/Swagger auto-documentation 🔧 Core Features: - Memory CRUD endpoints (POST, GET, DELETE) - User management and statistics - Search functionality with filtering - Admin endpoints with proper authorization 🔐 Security & Auth: - API key authentication (Bearer token) - Rate limiting (100 req/min configurable) - Input validation with Pydantic models - Comprehensive error handling 🧪 Testing: - Comprehensive test suite with automated server lifecycle - Simple test suite for quick validation - All functionality verified and working 🐛 Fixes: - Resolved Pydantic v2 compatibility (.dict() → .model_dump()) - Fixed missing dependencies (posthog, qdrant-client, vecs, ollama) - Fixed mem0 package version metadata issues 📊 Performance: - Async operations for scalability - Request timing middleware - Proper error boundaries - Health monitoring endpoints 🎯 Status: Phase 2 100% complete - REST API fully functional 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
62 lines
1.8 KiB
Python
Executable File
62 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Start the Mem0 API server
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import uvicorn
|
|
import logging
|
|
|
|
# Add current directory to path for imports
|
|
sys.path.insert(0, '/home/klas/mem0')
|
|
|
|
from api.main import app
|
|
|
|
# Configure logging
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def main():
|
|
"""Start the API server"""
|
|
|
|
# Set environment variables with defaults
|
|
os.environ.setdefault("API_HOST", "localhost")
|
|
os.environ.setdefault("API_PORT", "8080")
|
|
os.environ.setdefault("API_KEYS", "mem0_dev_key_123456789,mem0_test_key_987654321")
|
|
os.environ.setdefault("ADMIN_API_KEYS", "mem0_admin_key_111222333")
|
|
os.environ.setdefault("RATE_LIMIT_REQUESTS", "100")
|
|
os.environ.setdefault("RATE_LIMIT_WINDOW_MINUTES", "1")
|
|
|
|
host = os.getenv("API_HOST")
|
|
port = int(os.getenv("API_PORT"))
|
|
|
|
logger.info("=" * 60)
|
|
logger.info("🚀 STARTING MEM0 MEMORY SYSTEM API")
|
|
logger.info("=" * 60)
|
|
logger.info(f"📍 Server: http://{host}:{port}")
|
|
logger.info(f"📚 API Docs: http://{host}:{port}/docs")
|
|
logger.info(f"🔐 API Keys: {len(os.getenv('API_KEYS', '').split(','))} configured")
|
|
logger.info(f"👑 Admin Keys: {len(os.getenv('ADMIN_API_KEYS', '').split(','))} configured")
|
|
logger.info(f"⏱️ Rate Limit: {os.getenv('RATE_LIMIT_REQUESTS')}/min")
|
|
logger.info("=" * 60)
|
|
|
|
try:
|
|
uvicorn.run(
|
|
app,
|
|
host=host,
|
|
port=port,
|
|
log_level="info",
|
|
access_log=True
|
|
)
|
|
except KeyboardInterrupt:
|
|
logger.info("🛑 Server stopped by user")
|
|
except Exception as e:
|
|
logger.error(f"❌ Server failed to start: {e}")
|
|
sys.exit(1)
|
|
|
|
if __name__ == "__main__":
|
|
main() |