ADAPT-Chase's picture
Add files using upload-large-folder tool
3e626a5 verified
#!/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")