File size: 5,027 Bytes
4a329ac |
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
"""
Example client script for testing the LLM Code Deployment API
"""
import requests
import json
import time
from datetime import datetime
# Configuration
API_BASE_URL = "http://localhost:8000"
SHARED_SECRET = "your_shared_secret_here" # Replace with your actual secret
def test_health_check():
"""Test the health check endpoint"""
try:
response = requests.get(f"{API_BASE_URL}/health")
if response.status_code == 200:
print("β
Health check passed")
print(f"Response: {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
def test_app_generation():
"""Test the main app generation endpoint"""
# Generate a unique nonce
nonce = f"test_{int(time.time())}"
request_data = {
"email": "[email protected]",
"secret": SHARED_SECRET,
"task": "Create a simple calculator",
"round": 1,
"nonce": nonce,
"brief": "Create a basic calculator web app with addition, subtraction, multiplication, and division. Include a clean, modern interface with a display and number/operation buttons.",
"evaluation_url": "https://httpbin.org/post", # Test URL that echoes back requests
"attachments": []
}
try:
print("π Sending app generation request...")
response = requests.post(
f"{API_BASE_URL}/api/request",
json=request_data,
headers={"Content-Type": "application/json"}
)
if response.status_code == 200:
result = response.json()
print("β
App generation successful!")
print(f"Repository: {result['deployment']['repo_name']}")
print(f"Repository URL: {result['deployment']['repo_url']}")
print(f"GitHub Pages: {result['deployment']['pages_url']}")
print(f"Commit SHA: {result['deployment']['commit_sha']}")
return result
else:
print(f"β App generation failed: {response.status_code}")
print(f"Error: {response.text}")
return None
except Exception as e:
print(f"β Request error: {e}")
return None
def test_evaluation_endpoint():
"""Test the evaluation endpoint"""
evaluation_data = {
"email": "[email protected]",
"task": "Create a simple calculator",
"round": 1,
"nonce": f"test_{int(time.time())}",
"evaluation_data": {
"score": 85,
"feedback": "Good functionality, clean interface",
"suggestions": ["Add keyboard support", "Improve mobile responsiveness"]
}
}
try:
print("π Sending evaluation data...")
response = requests.post(
f"{API_BASE_URL}/api/evaluate",
json=evaluation_data,
headers={"Content-Type": "application/json"}
)
if response.status_code == 200:
print("β
Evaluation data received successfully!")
print(f"Response: {response.json()}")
return True
else:
print(f"β Evaluation failed: {response.status_code}")
return False
except Exception as e:
print(f"β Evaluation error: {e}")
return False
def main():
"""Run example client tests"""
print("π§ͺ LLM Code Deployment API Test Client")
print("=" * 50)
# Check if server is running
if not test_health_check():
print("\nβ Server is not running or not accessible")
print("Please start the server with: python main.py")
return
print("\n" + "=" * 50)
# Test app generation
result = test_app_generation()
if result:
print("\n" + "=" * 50)
# Test evaluation endpoint
test_evaluation_endpoint()
print("\n" + "=" * 50)
print("π All tests completed!")
if result.get('deployment', {}).get('pages_url'):
print(f"\nπ Your generated app is available at:")
print(f" {result['deployment']['pages_url']}")
print(f"\nπ Repository: {result['deployment']['repo_url']}")
else:
print("\nβ Tests failed. Please check your configuration.")
if __name__ == "__main__":
print("β οΈ Make sure to update SHARED_SECRET in this script!")
print("β οΈ Make sure the server is running on http://localhost:8000")
print()
# Uncomment the line below to run the tests
# main()
print("To run the tests, uncomment the main() call at the bottom of this file")
print("and update the SHARED_SECRET variable with your actual secret.")
|