From d20a7d5878354577b5076e9ebb5ea0e0746db613 Mon Sep 17 00:00:00 2001 From: chrischristiansen-glitch Date: Sun, 24 May 2026 14:31:42 +0200 Subject: [PATCH] =?UTF-8?q?fix:=2007-rag-setup.sh=20=E2=80=94=20bruk=20pro?= =?UTF-8?q?ject-number=20(ikke=20project-ID)=20i=20importRagFiles=20URL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- infrastructure/07-rag-setup.sh | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/infrastructure/07-rag-setup.sh b/infrastructure/07-rag-setup.sh index 54e5613..85ae9fb 100644 --- a/infrastructure/07-rag-setup.sh +++ b/infrastructure/07-rag-setup.sh @@ -28,6 +28,11 @@ gcloud services enable aiplatform.googleapis.com \ --project="${PROJECT_ID}" --quiet echo "✓ APIs enabled" +# ── Hent project-number (kræves av importRagFiles-endepunktet) ──────────────── +PROJECT_NUMBER=$(gcloud projects describe "${PROJECT_ID}" \ + --format='value(projectNumber)' 2>/dev/null) +echo " Project number: ${PROJECT_NUMBER}" + # ── GCS bucket (idempotent) ───────────────────────────────────────────── CORPUS_BUCKET="${PROJECT_ID}-agent-corpus" if ! gsutil ls -b "gs://${CORPUS_BUCKET}" &>/dev/null; then @@ -69,10 +74,9 @@ if [[ -f "${REPO_ROOT}/MASTERPLAN.md" ]]; then echo "✓ MASTERPLAN.md → gs://${CORPUS_BUCKET}/MASTERPLAN.md" UPLOAD_COUNT=$((UPLOAD_COUNT + 1)) fi - echo " Totalt ${UPLOAD_COUNT} filer synkronisert" -# ── REST: hent/opprett corpus ─────────────────────────────────────────────────── +# ── REST: hent/opprett corpus (bruker project-ID for listing/oppretting) ──────── TOKEN=$(gcloud auth print-access-token) BASE_URL="https://${RAG_REGION}-aiplatform.googleapis.com/v1beta1" PARENT="projects/${PROJECT_ID}/locations/${RAG_REGION}" @@ -99,10 +103,8 @@ else -H "Content-Type: application/json" \ "${BASE_URL}/${PARENT}/ragCorpora" \ -d '{"displayName":"'"${RAG_CORPUS_DISPLAY_NAME}"'","ragEmbeddingModelConfig":{"vertexPredictionEndpoint":{"publisherModel":"publishers/google/models/text-embedding-005"}},"ragVectorDbConfig":{"ragManagedDb":{}}}') - OPERATION=$(echo "${RESPONSE}" | python3 -c "import sys,json; print(json.load(sys.stdin).get('name',''))" 2>/dev/null || true) [[ -z "${OPERATION}" ]] && { echo "ERROR: ${RESPONSE}"; exit 1; } - echo " Venter på LRO..." for i in $(seq 1 30); do sleep 10 @@ -126,15 +128,19 @@ for c in data.get('ragCorpora',[]): [[ -z "${CORPUS_NAME}" ]] && { echo "ERROR: timed out"; exit 1; } fi -# ── Import: CORPUS_NAME er full ressurssti — bruk direkte som URL-path ───────── -# Korrekt URL: https://{region}-aiplatform.googleapis.com/v1beta1/{corpus_name}:importRagFiles -IMPORT_URL="https://${RAG_REGION}-aiplatform.googleapis.com/v1beta1/${CORPUS_NAME}:importRagFiles" +# Hent corpus-ID (siste del av ressursstien) +CORPUS_ID=$(echo "${CORPUS_NAME}" | rev | cut -d'/' -f1 | rev) + +# ── Import: bygg URL med project-NUMBER (ikke project-ID) ─────────────────────── +# importRagFiles krever project-number i stien +IMPORT_URL="https://${RAG_REGION}-aiplatform.googleapis.com/v1beta1/projects/${PROJECT_NUMBER}/locations/${RAG_REGION}/ragCorpora/${CORPUS_ID}:importRagFiles" +echo " Import URL: ${IMPORT_URL}" IMPORT_OK=0 for GCS_PATH in "seed/" "docs/" "sessions/" "MASTERPLAN.md"; do GCS_URI="gs://${CORPUS_BUCKET}/${GCS_PATH}" if gsutil ls "${GCS_URI}" &>/dev/null; then - HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST \ + HTTP_STATUS=$(curl -s -o /tmp/import_response.json -w "%{http_code}" -X POST \ -H "Authorization: Bearer ${TOKEN}" \ -H "Content-Type: application/json" \ "${IMPORT_URL}" \ @@ -144,10 +150,11 @@ for GCS_PATH in "seed/" "docs/" "sessions/" "MASTERPLAN.md"; do IMPORT_OK=$((IMPORT_OK + 1)) else echo " ADVARSEL: Import feilet (HTTP ${HTTP_STATUS}): ${GCS_URI}" + cat /tmp/import_response.json 2>/dev/null || true fi fi done -echo " ${IMPORT_OK} import-jobber trigget (async — indeksering tar noen minutter)" +echo " ${IMPORT_OK}/4 import-jobber trigget (async — indeksering tar noen minutter)" # ── Output ───────────────────────────────────────────────────────────────── echo "${CORPUS_NAME}" > /tmp/rag_corpus_name.txt