49 lines
2.3 KiB
Bash
49 lines
2.3 KiB
Bash
#!/usr/bin/env bash
|
|
# Brain stack helpers: render env, align postgres password, create atomic token,
|
|
# seed the canonical taxonomy. Idempotent. Requires lib.sh sourced + master .env
|
|
# loaded ($POSTGRES_PASSWORD, $ATOMIC_TOKEN, $HOST_IP, $ENV_FILE, $BRAIN_DIR).
|
|
|
|
# Write didi_brain/.env (read by brain-api/scheduler) + infra/.env (compose interpolation)
|
|
brain_write_env() {
|
|
local pw=$1 tok=$2
|
|
cp "${BRAIN_DIR}/.env.example" "${BRAIN_DIR}/.env"
|
|
sed -i \
|
|
-e "s#^LLM_ROUTER_URL=.*#LLM_ROUTER_URL=http://didiAI-llm-api:14011#" \
|
|
-e "s#^LLM_VLLM_URL=.*#LLM_VLLM_URL=http://didiAI-vllm-qwen3.5:14001#" \
|
|
-e "s#^EMBEDDING_URL=.*#EMBEDDING_URL=http://didiAI-embeddings-api:14100#" \
|
|
-e "s#^RERANKER_URL=.*#RERANKER_URL=http://didiAI-rerank-api:14200#" \
|
|
-e "s#^MODEL_FAST_ENABLED=.*#MODEL_FAST_ENABLED=true#" \
|
|
-e "s#^POSTGRES_PASSWORD=.*#POSTGRES_PASSWORD=${pw}#" \
|
|
"${BRAIN_DIR}/.env"
|
|
if grep -q '^ATOMIC_TOKEN=' "${BRAIN_DIR}/.env"; then
|
|
sed -i "s#^ATOMIC_TOKEN=.*#ATOMIC_TOKEN=${tok}#" "${BRAIN_DIR}/.env"
|
|
else
|
|
echo "ATOMIC_TOKEN=${tok}" >> "${BRAIN_DIR}/.env"
|
|
fi
|
|
printf 'POSTGRES_USER=atomic\nPOSTGRES_PASSWORD=%s\nPOSTGRES_DB=atomic\n' "$pw" > "${BRAIN_DIR}/infra/.env"
|
|
}
|
|
|
|
# Force the postgres role password to match (volume may have been initialized with a different one)
|
|
brain_align_pg() {
|
|
local pw=$1
|
|
docker exec didibrain-postgres psql -U atomic -d atomic \
|
|
-c "ALTER USER atomic WITH PASSWORD '${pw}';" >/dev/null 2>&1 || true
|
|
}
|
|
|
|
# Create an atomic API token if the master .env doesn't have one yet. Echos the token.
|
|
brain_ensure_token() {
|
|
local pw=$1 cur=$2
|
|
if [ -n "$cur" ]; then printf '%s' "$cur"; return 0; fi
|
|
local out tok
|
|
out=$(docker exec didibrain-atomic atomic-server token create --name didibrain \
|
|
--storage postgres --database-url "postgres://atomic:${pw}@postgres:5432/atomic" 2>&1)
|
|
tok=$(printf '%s' "$out" | grep -oE 'at_[A-Za-z0-9_.-]{20,}' | head -1)
|
|
printf '%s' "$tok"
|
|
}
|
|
|
|
# Seed canonical taxonomy into atomic (idempotent; tags created if missing).
|
|
brain_seed_taxonomy() {
|
|
docker cp "${BRAIN_DIR}/scripts" didibrain-api:/app/scripts >/dev/null 2>&1 || true
|
|
# local _tag_ids.json write is read-only in the image — harmless, atomic gets the tags
|
|
docker exec -e PYTHONPATH=/app didibrain-api python /app/scripts/04_seed_taxonomy.py >/dev/null 2>&1 || true
|
|
}
|