File size: 3,636 Bytes
b30f068 | 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 | #!/usr/bin/env python3
"""
Simple test script for the API (no Docker needed).
Run this after starting the API server.
"""
import requests
import json
import time
def test_api():
"""Test the API endpoints."""
base_url = "http://localhost:8000"
headers = {
"Authorization": "Bearer demo-key-12345",
"Content-Type": "application/json"
}
print("π§ͺ Testing Agentic AI API")
print("=" * 40)
try:
# 1. Health check
print("\\n1. Health Check...")
response = requests.get(f"{base_url}/health")
if response.status_code == 200:
health = response.json()
print(f" β
Status: {health['status']}")
print(f" β±οΈ Uptime: {health['uptime']:.1f}s")
else:
print(f" β Health check failed: {response.status_code}")
return
# 2. Process a query
print("\\n2. Processing Query...")
query_data = {
"query": "Find machine learning datasets for image classification",
"include_debug": True,
"max_api_calls": 3
}
response = requests.post(
f"{base_url}/query",
headers=headers,
json=query_data
)
if response.status_code == 200:
result = response.json()
print(f" β
Success in {result['processing_time']:.3f}s")
print(f" π Request ID: {result['request_id']}")
# Show results
results = result['results']
query_info = results.get('query', {})
api_matches = results.get('api_matches', {})
print(f" π Keywords: {query_info.get('keywords', [])[:3]}")
print(f" π― Intent: {query_info.get('intent')}")
print(f" π API Matches: {api_matches.get('count', 0)}")
print(f" π Summary: {results.get('summary', 'N/A')[:60]}...")
else:
print(f" β Query failed: {response.status_code}")
print(f" Error: {response.text}")
# 3. List APIs
print("\\n3. Available APIs...")
response = requests.get(f"{base_url}/apis", headers=headers)
if response.status_code == 200:
apis = response.json()
print(f" β
Found {len(apis)} APIs:")
for api in apis[:3]:
print(f" β’ {api['name']} ({api['method']} {api['endpoint']})")
# 4. Extract keywords
print("\\n4. Keyword Extraction...")
test_query = "Create a new neural network for classification"
response = requests.get(
f"{base_url}/keywords/{test_query}",
headers=headers
)
if response.status_code == 200:
keywords = response.json()
print(f" β
Extracted {keywords['count']} keywords:")
print(f" {keywords['keywords'][:5]}")
print("\\n" + "=" * 40)
print("π All tests passed!")
print("\\nπ‘ Try these URLs in your browser:")
print(f" π API Docs: {base_url}/docs")
print(f" π Health: {base_url}/health")
except requests.exceptions.ConnectionError:
print("\\nβ Cannot connect to API server!")
print("π‘ Start the server first:")
print(" python run_api.py")
except Exception as e:
print(f"\\nβ Test failed: {e}")
if __name__ == "__main__":
test_api()
|