ragserver/build.sh

90 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
set -e
cdir=$(cd "$(dirname "$0")"; pwd)
# Environment
export SAGE_RBAC_DB=rag
# Virtualenv
if [ ! -d py3 ]; then
python3 -m venv py3
fi
source py3/bin/activate
# Install build tools
pip install -q xls2ddl
# pkgs directory
mkdir -p pkgs logs files
# Clone and install foundation modules
for repo in apppublic sqlor ahserver rbac appbase bricks-for-python; do
[ -d pkgs/$repo ] || git clone git@git.opencomputing.cn:yumoqing/$repo.git pkgs/$repo
pip install -q -e pkgs/$repo
done
# Clone and install rag-pipeline (core engine - add to PYTHONPATH, not pip install)
[ -d pkgs/rag-pipeline ] || git clone git@git.opencomputing.cn:yumoqing/rag-pipeline.git pkgs/rag-pipeline
# rag-pipeline is imported directly, not via pip
# Clone service modules (for reference, not imported)
for svc in clip_embedding vdb face-service graph-service ner-service; do
[ -d pkgs/$svc ] || git clone git@git.opencomputing.cn:yumoqing/$svc.git pkgs/$svc 2>/dev/null || echo "Skip $svc (repo may not exist yet)"
done
# bge-reranker and speaker-id repos may not exist yet
[ -d pkgs/bge-reranker ] || git clone git@git.opencomputing.cn:yumoqing/bge-reranker.git pkgs/bge-reranker 2>/dev/null || echo "Skip bge-reranker"
[ -d pkgs/speaker-id ] || git clone git@git.opencomputing.cn:yumoqing/speaker-id.git pkgs/speaker-id 2>/dev/null || echo "Skip speaker-id"
# Build bricks frontend
if [ ! -d pkgs/bricks ]; then
git clone git@git.opencomputing.cn:yumoqing/bricks.git pkgs/bricks
fi
mkdir -p pkgs/bricks/dist/i18n
cd pkgs/bricks
bash build.sh
cd $cdir
# Symlink bricks
ln -sf ../pkgs/bricks/dist wwwroot/bricks 2>/dev/null || true
# Install appbase and rbac
pip install -q -e pkgs/appbase
pip install -q -e pkgs/rbac
# Generate DDL from models
if ls models/*.json >/dev/null 2>&1; then
cd models
json2ddl mysql . > mysql.ddl.sql
mysql -h db -utest -ptest123 rag < mysql.ddl.sql 2>/dev/null || echo "DDL already applied or mysql not available"
cd $cdir
fi
# Generate CRUD from json/
if ls json/*.json >/dev/null 2>&1; then
xls2ui -m models -o wwwroot ragserver json/*.json 2>/dev/null || true
fi
# Symlink module wwwroots
for m in rag-pipeline; do
[ -d pkgs/$m/wwwroot ] && ln -sf ../pkgs/$m/wwwroot wwwroot/$m 2>/dev/null || true
done
# Fix created_by in CRUD dspy files
if [ -d wwwroot/knowledge_bases_list ]; then
find wwwroot -name '*.dspy' -exec sed -i "s/ns\['created_by'\] = ''/ns['created_by'] = userorgid/" {} \; 2>/dev/null || true
fi
# Sync password_key from Sage if available
if [ -f /d/apitest/sage/conf/config.json ]; then
sage_key=$(python3 -c "import json; print(json.load(open('/d/apitest/sage/conf/config.json'))['password_key'])")
python3 -c "
import json
c = json.load(open('$cdir/conf/config.json'))
c['password_key'] = '$sage_key'
json.dump(c, open('$cdir/conf/config.json', 'w'), indent=4)
"
echo "password_key synced from Sage"
fi
echo "=== RAG Server build complete ==="