File size: 1,549 Bytes
aca8ab4 |
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 |
#!/bin/bash
# Test Azure OpenAI embedding deployment directly via curl
# Load environment variables
set -a
source .env 2>/dev/null || true
set +a
ENDPOINT="${AZURE_OPENAI_ENDPOINT}"
API_KEY="${AZURE_OPENAI_API_KEY}"
DEPLOYMENT_NAME="${AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME}"
API_VERSION="${AZURE_OPENAI_API_VERSION:-2024-02-01}"
echo "=================================="
echo "Testing Azure OpenAI Embedding Deployment"
echo "=================================="
echo ""
echo "Endpoint: $ENDPOINT"
echo "Deployment: $DEPLOYMENT_NAME"
echo "API Version: $API_VERSION"
echo ""
echo "Sending test request..."
echo ""
# Make the embedding request
curl -X POST "${ENDPOINT}openai/deployments/${DEPLOYMENT_NAME}/embeddings?api-version=${API_VERSION}" \
-H "Content-Type: application/json" \
-H "api-key: ${API_KEY}" \
-d '{
"input": "This is a test embedding request"
}' 2>&1 | python3 -c "
import sys, json
try:
data = json.load(sys.stdin)
if 'error' in data:
print('❌ ERROR:')
print(json.dumps(data, indent=2))
sys.exit(1)
elif 'data' in data:
embedding_dim = len(data['data'][0]['embedding'])
print('✅ SUCCESS!')
print(f' Embedding dimension: {embedding_dim}')
print(f' Model: {data.get(\"model\", \"unknown\")}')
print(f' Usage tokens: {data.get(\"usage\", {}).get(\"total_tokens\", 0)}')
sys.exit(0)
except Exception as e:
print(f'❌ Failed to parse response: {e}')
sys.exit(1)
"
echo ""
echo "=================================="
|