| |
| """ |
| 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" |
| } |
| |
| |
| 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) |
| |
| |
| if test_health(): |
| |
| 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") |