#!/usr/bin/env bash # 在 207 上部署 LiteLLM Proxy(pip + systemd;Docker 镜像拉取不稳定时的主路径) set -euo pipefail export PIP_INDEX_URL="${PIP_INDEX_URL:-https://pypi.tuna.tsinghua.edu.cn/simple}" export PIP_TRUSTED_HOST="${PIP_TRUSTED_HOST:-pypi.tuna.tsinghua.edu.cn}" PATCH="/opt/workbuddy/patches_cursor/LiteLLM部署" CFG_SRC="${PATCH}/config.yaml" CFG_DST="/opt/litellm/config.yaml" VENV="/opt/litellm-venv" if [ ! -f "$CFG_SRC" ]; then echo "[FAIL] 缺少 $CFG_SRC" exit 1 fi if [ ! -x "${VENV}/bin/pip" ]; then python3 -m venv "$VENV" fi "${VENV}/bin/pip" install -U pip # 1.74.x 在 Ubuntu 的 Python 3.10 上更稳(新版有 typing 兼容问题) "${VENV}/bin/pip" install 'litellm[proxy]==1.74.15' mkdir -p /opt/litellm cp -f "$CFG_SRC" "$CFG_DST" # 本机进程访问本机 Xinference sed -i 's#http://host.docker.internal:9997/v1#http://127.0.0.1:9997/v1#g' "$CFG_DST" docker rm -f litellm 2>/dev/null || true cat >/etc/systemd/system/litellm.service <<'EOF' [Unit] Description=LiteLLM OpenAI Proxy After=network-online.target Wants=network-online.target [Service] Type=simple Environment=LITELLM_MASTER_KEY=sk-litellm-bocheng-207 Environment=LITELLM_LOG=INFO WorkingDirectory=/opt/litellm ExecStart=/opt/litellm-venv/bin/litellm --config /opt/litellm/config.yaml --port 4000 --host 0.0.0.0 Restart=on-failure RestartSec=5 LimitNOFILE=65535 [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable litellm.service systemctl restart litellm.service ok=0 for i in $(seq 1 40); do if curl -sf "http://127.0.0.1:4000/health/liveliness" >/dev/null 2>&1; then ok=1 break fi sleep 2 done systemctl --no-pager --full status litellm.service | head -n 20 || true if [ "$ok" != "1" ]; then echo "[FAIL] LiteLLM 健康检查超时" journalctl -u litellm.service -n 80 --no-pager || true exit 1 fi echo "[OK] LiteLLM http://192.168.110.207:4000" echo "[OK] master key: sk-litellm-bocheng-207" echo "[OK] models: qwen3.6-27b / qwen / bge-m3"