File size: 2,667 Bytes
883ffeb | 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 | #!/bin/bash
# Quick test script - tests async API with Google Drive upload
# Usage: ./quick_test.sh YOUR_GOOGLE_ACCESS_TOKEN
set -e
GOOGLE_TOKEN=$1
BASE_URL=${2:-"http://localhost:8000"}
if [ -z "$GOOGLE_TOKEN" ]; then
echo "Usage: ./quick_test.sh YOUR_GOOGLE_ACCESS_TOKEN [BASE_URL]"
echo ""
echo "To get a Google token, run:"
echo " python test_get_google_token.py --client-id YOUR_ID --client-secret YOUR_SECRET"
echo ""
echo "Or see TESTING.md for detailed instructions"
exit 1
fi
echo "==========================================="
echo "Quick Test: Async API + Google Drive"
echo "==========================================="
echo "API: $BASE_URL"
echo "Token: ${GOOGLE_TOKEN:0:20}..."
echo ""
# Step 1: Health check
echo "1. Health Check..."
curl -s "$BASE_URL/health" | python -m json.tool
echo ""
# Step 2: Submit job
echo "2. Submitting Job..."
RESPONSE=$(curl -s -X POST "$BASE_URL/generate/async" \
-H "Content-Type: application/json" \
-d "{
\"user_id\": 1,
\"google_drive_token\": \"$GOOGLE_TOKEN\",
\"seed_images\": [\"https://ocr.space/Content/Images/receipt-ocr-original.webp\"],
\"prompt_params\": {
\"language\": \"English\",
\"doc_type\": \"receipts\",
\"num_solutions\": 1,
\"enable_handwriting\": false,
\"enable_visual_elements\": false,
\"output_detail\": \"minimal\"
}
}")
echo "$RESPONSE" | python -m json.tool
echo ""
REQUEST_ID=$(echo "$RESPONSE" | python -c "import sys, json; print(json.load(sys.stdin)['request_id'])" 2>/dev/null || echo "")
if [ -z "$REQUEST_ID" ]; then
echo "✗ Failed to submit job"
exit 1
fi
echo "✓ Job ID: $REQUEST_ID"
echo ""
# Step 3: Poll status
echo "3. Polling Status (will check 5 times, 10s apart)..."
for i in {1..5}; do
echo " Poll $i/5..."
STATUS=$(curl -s "$BASE_URL/jobs/$REQUEST_ID/status")
CURRENT_STATUS=$(echo "$STATUS" | python -c "import sys, json; print(json.load(sys.stdin)['status'])" 2>/dev/null || echo "unknown")
echo " Status: $CURRENT_STATUS"
if [ "$CURRENT_STATUS" = "completed" ]; then
echo ""
echo "✓ JOB COMPLETED!"
echo "$STATUS" | python -m json.tool
exit 0
elif [ "$CURRENT_STATUS" = "failed" ]; then
echo ""
echo "✗ JOB FAILED"
echo "$STATUS" | python -m json.tool
exit 1
fi
if [ $i -lt 5 ]; then
sleep 10
fi
done
echo ""
echo "⏱ Job still in progress. Continue polling manually:"
echo " curl $BASE_URL/jobs/$REQUEST_ID/status"
echo ""
echo "Or use the full test script:"
echo " python test_async_api.py --google-token $GOOGLE_TOKEN"
|