Skip to content

armgit / ODS

Public Imported from GitHub
0

ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.

4.8 KB
Raw Blame
services:
  litellm:
    # v1.90.7 closes the upstream provider stream when a client disconnects,
    # so Pixel Stop releases the exact llama.cpp request instead of decoding
    # into a dead socket. Pin the reviewed multi-arch manifest, not just a tag.
    image: ghcr.io/berriai/litellm:v1.90.7@sha256:917d480b7e4a7e61822e54f70be5c7cf753fb0b7328cbf6467612652ca748075
    container_name: ods-litellm
    restart: unless-stopped
    # remote-provider (declared in docker-compose.base.yml) reaches the
    # remote-provider egress; it is internal, so ods-network stays the
    # default route for local and host-side model backends.
    networks:
      - default
      - remote-provider
    security_opt:
      - no-new-privileges:true
    environment:
      - LITELLM_MASTER_KEY=${LITELLM_KEY:-}
      # Use the cost map bundled in the pinned image instead of fetching it
      # from GitHub at every start.
      - LITELLM_LOCAL_MODEL_COST_MAP=True
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:-}
      - OPENAI_API_KEY=${OPENAI_API_KEY:-}
      - TOGETHER_API_KEY=${TOGETHER_API_KEY:-}
      - MINIMAX_API_KEY=${MINIMAX_API_KEY:-}
      - LANGFUSE_ENABLED=${LANGFUSE_ENABLED:-false}
      - ODS_MODE=${ODS_MODE:-local}
      - ODS_MODEL_SWITCHBOARD=${ODS_MODEL_SWITCHBOARD:-enabled}
      - TOKEN_SPY_URL=${TOKEN_SPY_URL:-http://token-spy:8080}
      - TOKEN_SPY_API_KEY=${TOKEN_SPY_API_KEY:-}
      # A Windows AMD install's LiteLLM config sends this bearer key to the
      # native llama-server (os.environ/LLAMA_SERVER_API_KEY). Only those
      # installs set it; it is empty, and unused, everywhere else.
      - LLAMA_SERVER_API_KEY=${LLAMA_SERVER_API_KEY:-}
    volumes:
      - ./config/litellm/${ODS_MODE:-local}.yaml:/app/config.yaml:ro,z
      - ./config/litellm/switchboard.yaml:/app/switchboard.yaml:ro,z
      - ./extensions/services/litellm/select-config.sh:/app/ods-select-config.sh:ro,z
      # LiteLLM resolves custom callback modules relative to the generated
      # /tmp/config.yaml, so the callback must be mounted alongside it.
      - ./extensions/services/litellm/ods_token_spy_callback.py:/tmp/ods_token_spy_callback.py:ro,z
    ports:
      - "127.0.0.1:${LITELLM_PORT:-4000}:4000"
    entrypoint: ["/bin/sh", "-c"]
    command:
      - |
        if [ -s /run/secrets/ods-external-llm-api-key ]; then
          export EXTERNAL_LLM_API_KEY="$$(cat /run/secrets/ods-external-llm-api-key)"
        fi
        CONFIG_PATH=$$(sh /app/ods-select-config.sh)
        if [ -z "$$CONFIG_PATH" ] || [ ! -r "$$CONFIG_PATH" ]; then
          echo "ERROR: LiteLLM config selector returned an unreadable path: $${CONFIG_PATH:-<empty>}" >&2
          exit 1
        fi
        export CONFIG_PATH
        python3 -c "
        import os
        import yaml
        with open(os.environ['CONFIG_PATH']) as f:
            cfg = yaml.safe_load(f)
        settings = cfg.setdefault('litellm_settings', {})
        callbacks = settings.get('callbacks', [])
        if not isinstance(callbacks, list):
            callbacks = []
        if os.environ.get('TOKEN_SPY_URL') and os.environ.get('TOKEN_SPY_API_KEY'):
            callbacks.append('ods_token_spy_callback.ods_token_spy_callback')
        settings['callbacks'] = list(dict.fromkeys(callbacks))
        if os.environ.get('LANGFUSE_ENABLED') == 'true':
            success_callbacks = settings.get('success_callback', [])
            if not isinstance(success_callbacks, list):
                success_callbacks = []
            success_callbacks.append('langfuse')
            settings['success_callback'] = list(dict.fromkeys(success_callbacks))
        # The remote-provider egress admits only the gateway key. Older
        # rendered configs say not-needed, and an unset key must not fall
        # back to OPENAI_API_KEY, so set it here for every egress route.
        egress_key = 'os.environ/LITELLM_MASTER_KEY' if os.environ.get('LITELLM_MASTER_KEY') else 'ods-gateway-key-missing'
        for model in cfg.get('model_list') or []:
            params = model.get('litellm_params') if isinstance(model, dict) else None
            if isinstance(params, dict) and str(params.get('api_base') or '').startswith('http://remote-provider-egress:'):
                params['api_key'] = egress_key
        with open('/tmp/config.yaml', 'w') as f:
            yaml.dump(cfg, f, default_flow_style=False)
        "
        exec litellm --config /tmp/config.yaml --port 4000
    deploy:
      resources:
        limits:
          cpus: '1.0'
          memory: 2G
        reservations:
          cpus: '0.25'
          memory: 512M
    healthcheck:
      test: ["CMD", "python3", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:4000/health/readiness', timeout=5)"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 20s
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"