-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api.sh
More file actions
executable file
·112 lines (84 loc) · 2.76 KB
/
Copy pathtest-api.sh
File metadata and controls
executable file
·112 lines (84 loc) · 2.76 KB
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
95
96
97
98
99
100
#!/bin/bash
# Morpheus API Test Script
# Usage: ./test-api.sh YOUR_API_KEY
if [ -z "$1" ]; then
echo "❌ Error: API key required"
echo "Usage: ./test-api.sh YOUR_API_KEY"
exit 1
fi
API_KEY="$1"
BASE_URL="https://api.mor.org/api/v1"
echo "🚀 Testing Morpheus API Gateway"
echo "================================"
echo ""
# Test 1: List Models
echo "📋 Test 1: List Models"
echo "Endpoint: GET $BASE_URL/models"
echo ""
RESPONSE=$(curl -s -w "\nHTTP_CODE:%{http_code}" \
-X GET "$BASE_URL/models" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json")
HTTP_CODE=$(echo "$RESPONSE" | grep "HTTP_CODE:" | cut -d: -f2)
BODY=$(echo "$RESPONSE" | sed '/HTTP_CODE:/d')
if [ "$HTTP_CODE" = "200" ]; then
echo "✅ Status: $HTTP_CODE OK"
echo "$BODY" | python3 -m json.tool 2>/dev/null | head -20
MODEL_COUNT=$(echo "$BODY" | python3 -c "import sys, json; print(len(json.load(sys.stdin).get('data', [])))" 2>/dev/null)
echo "..."
echo "Total models: $MODEL_COUNT"
else
echo "❌ Status: $HTTP_CODE"
echo "$BODY" | python3 -m json.tool 2>/dev/null || echo "$BODY"
fi
echo ""
echo "================================"
echo ""
# Test 2: Chat Completion
echo "💬 Test 2: Chat Completion"
echo "Endpoint: POST $BASE_URL/chat/completions"
echo ""
RESPONSE=$(curl -s -w "\nHTTP_CODE:%{http_code}" \
-X POST "$BASE_URL/chat/completions" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "llama-3.3-70b",
"messages": [
{"role": "user", "content": "Say hello in one sentence!"}
],
"max_tokens": 50
}')
HTTP_CODE=$(echo "$RESPONSE" | grep "HTTP_CODE:" | cut -d: -f2)
BODY=$(echo "$RESPONSE" | sed '/HTTP_CODE:/d')
if [ "$HTTP_CODE" = "200" ]; then
echo "✅ Status: $HTTP_CODE OK"
echo "$BODY" | python3 -m json.tool 2>/dev/null
else
echo "❌ Status: $HTTP_CODE"
echo "$BODY" | python3 -m json.tool 2>/dev/null || echo "$BODY"
fi
echo ""
echo "================================"
echo ""
# Test 3: CORS Check
echo "🔒 Test 3: CORS Configuration"
echo "Endpoint: GET https://api.mor.org/cors-check"
echo ""
RESPONSE=$(curl -s -w "\nHTTP_CODE:%{http_code}" \
-X GET "https://api.mor.org/cors-check" \
-H "Authorization: Bearer $API_KEY" \
-H "Origin: http://localhost:8080")
HTTP_CODE=$(echo "$RESPONSE" | grep "HTTP_CODE:" | cut -d: -f2)
BODY=$(echo "$RESPONSE" | sed '/HTTP_CODE:/d')
if [ "$HTTP_CODE" = "200" ]; then
echo "✅ Status: $HTTP_CODE OK"
echo "$BODY" | python3 -m json.tool 2>/dev/null
else
echo "❌ Status: $HTTP_CODE"
echo "$BODY" | python3 -m json.tool 2>/dev/null || echo "$BODY"
fi
echo ""
echo "================================"
echo "✨ Testing complete!"
echo ""