#!/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")