Spaces:
Runtime error
Runtime error
File size: 2,775 Bytes
851f2ed 929235c 7414a53 929235c 7414a53 929235c 7414a53 929235c 695b33f 929235c 695b33f 929235c 695b33f 929235c 695b33f 929235c 695b33f 929235c 695b33f 929235c 695b33f 929235c 695b33f 851f2ed 695b33f 929235c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #!/usr/bin/env bash
set -euo pipefail
if [ -d "/data" ]; then
DEFAULT_STORAGE_ROOT="/data/rag_storage"
DEFAULT_HF_HOME="/data/.huggingface"
else
DEFAULT_STORAGE_ROOT="data/rag_storage"
DEFAULT_HF_HOME="/tmp/.cache/huggingface"
fi
export HF_HOME="${HF_HOME:-$DEFAULT_HF_HOME}"
export LIGHTRAG_STORAGE_ROOT="${LIGHTRAG_STORAGE_ROOT:-$DEFAULT_STORAGE_ROOT}"
JURISDICTIONS="${JURISDICTIONS:-romania,bahrain}"
HOST="${LIGHTRAG_HOST:-127.0.0.1}"
ROOT="${LIGHTRAG_STORAGE_ROOT}"
GRAPHS="${LIGHTRAG_GRAPHS:-romania:9621,bahrain:9622}"
API_PORT="${PORT:-${API_PORT:-8000}}"
mkdir -p "${ROOT}"
mkdir -p "${HF_HOME}"
echo "π Storage root: ${ROOT}"
echo "πΎ HF_HOME: ${HF_HOME}"
echo "π JURISDICTIONS=${JURISDICTIONS}"
echo "π LIGHTRAG_GRAPHS=${GRAPHS}"
echo "π₯ Checking for knowledge graph data..."
missing=0
missing_jurs=()
IFS=',' read -r -a jurisdictions <<< "${JURISDICTIONS}"
for jur in "${jurisdictions[@]}"; do
jur="$(echo "$jur" | xargs)"
if [ ! -d "${ROOT}/${jur}" ]; then
echo " β Missing: ${ROOT}/${jur}"
missing=1
missing_jurs+=("${jur}")
else
file_count=$(find "${ROOT}/${jur}" -type f | wc -l)
echo " β
Found: ${ROOT}/${jur} (${file_count} files)"
fi
done
if [ "${missing}" -eq 1 ]; then
echo ""
echo "π Downloading knowledge graph from Hugging Face..."
echo " π Missing jurisdictions: ${missing_jurs[*]}"
echo " β³ Starting download process..."
echo ""
if python scripts/download_knowledge_graph.py; then
echo ""
echo "β
Knowledge graph download complete"
else
echo ""
echo "β Knowledge graph download failed"
exit 1
fi
else
echo ""
echo "β
All knowledge graph data already present, skipping download"
fi
echo ""
PIDS=()
trap 'kill -TERM ${PIDS[@]:-} 2>/dev/null || true; wait ${PIDS[@]:-} 2>/dev/null || true' EXIT INT TERM
ENDPOINTS=()
IFS=',' read -r -a items <<< "${GRAPHS}"
for item in "${items[@]}"; do
IFS=':' read -r id port <<< "${item}"
dir="${ROOT}/${id}"
mkdir -p "${dir}"
echo "β‘οΈ Start LightRAG '${id}' on ${HOST}:${port} (dir=${dir})"
lightrag-server --host "${HOST}" --port "${port}" --working-dir "${dir}" &
PIDS+=("$!")
echo " β³ Waiting health for ${id}..."
ready=0
for _ in {1..60}; do
if curl -fsS "http://${HOST}:${port}/health" >/dev/null 2>&1; then
echo " β
${id} ready"
ready=1
break
fi
sleep 2
done
if [ "${ready}" -ne 1 ]; then
echo " β ${id} failed health check"
exit 1
fi
ENDPOINTS+=("${id}=http://${HOST}:${port}")
done
export LIGHTRAG_ENDPOINTS="$(IFS=,; echo "${ENDPOINTS[*]}")"
export PORT="${API_PORT}"
echo "β
LIGHTRAG_ENDPOINTS=${LIGHTRAG_ENDPOINTS}"
echo "π Starting API on 0.0.0.0:${PORT} ..."
python agent_api.py |