feat: Add handler-base library for NATS AI/ML services

- Handler base class with graceful shutdown and signal handling
- NATSClient with JetStream and msgpack serialization
- Pydantic Settings for environment configuration
- HealthServer for Kubernetes probes
- OpenTelemetry telemetry setup
- Service clients: STT, TTS, LLM, Embeddings, Reranker, Milvus
This commit is contained in:
2026-02-01 20:36:00 -05:00
parent 00df482412
commit 99c97b7973
17 changed files with 1932 additions and 1 deletions

58
Dockerfile Normal file
View File

@@ -0,0 +1,58 @@
# Handler Base Image
#
# Provides a pre-built base with all common dependencies for handler services.
# Services extend this image and add their specific code.
#
# Build:
# docker build -t ghcr.io/billy-davies-2/handler-base:latest .
#
# Usage in child Dockerfile:
# FROM ghcr.io/billy-davies-2/handler-base:latest
# COPY my_handler.py .
# CMD ["python", "my_handler.py"]
FROM python:3.13-slim AS base
WORKDIR /app
# Install uv for fast, reliable package management
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy and install handler-base package
COPY pyproject.toml README.md ./
COPY handler_base/ ./handler_base/
# Install the package with all dependencies
RUN uv pip install --system --no-cache .
# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
# Default health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Default command (override in child images)
CMD ["python", "-c", "print('handler-base ready')"]
# Audio variant with soundfile, librosa, webrtcvad
FROM base AS audio
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
libsndfile1 \
gcc \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
RUN uv pip install --system --no-cache \
soundfile>=0.12.0 \
librosa>=0.10.0 \
webrtcvad>=2.0.10