File size: 2,460 Bytes
3e626a5 |
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 |
#!/usr/bin/env python3
"""
Test script for Elizabeth OpenAI-compatible API.
"""
import requests
import json
import time
def test_api():
"""Test the API endpoint."""
url = "http://localhost:8000/v1/chat/completions"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer elizabeth-secret-key-2025"
}
# Test payload
payload = {
"model": "qwen3-8b-elizabeth-simple",
"messages": [
{"role": "user", "content": "Hello! How are you today?"}
],
"temperature": 0.7,
"max_tokens": 100
}
print("π§ͺ Testing API endpoint...")
try:
start_time = time.time()
response = requests.post(url, headers=headers, json=payload, timeout=30)
response_time = time.time() - start_time
if response.status_code == 200:
result = response.json()
print(f"β
API test successful! Response time: {response_time:.2f}s")
print(f"π¬ Response: {result['choices'][0]['message']['content']}")
print(f"π Usage: {result['usage']}")
return True
else:
print(f"β API test failed: {response.status_code}")
print(f"Response: {response.text}")
return False
except Exception as e:
print(f"β API test error: {e}")
return False
def test_health():
"""Test health endpoint."""
url = "http://localhost:8000/health"
try:
response = requests.get(url, timeout=5)
if response.status_code == 200:
print(f"β
Health check: {response.json()}")
return True
else:
print(f"β Health check failed: {response.status_code}")
return False
except Exception as e:
print(f"β Health check error: {e}")
return False
if __name__ == "__main__":
print("=" * 60)
print("π€ Elizabeth API Test")
print("=" * 60)
# Test health endpoint first
if test_health():
# Test chat completion
success = test_api()
print("\n" + "=" * 60)
if success:
print("π All API tests passed! Ready for tunneling.")
else:
print("β API tests failed. Check server status.")
print("=" * 60)
else:
print("β Health check failed. Start the server first:")
print("python serve.py") |