agAdvisor / test_api_simple.py
tirtho149's picture
Deploy AgAdvisor
b30f068 verified
Raw
History Blame Contribute Delete
3.64 kB
#!/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()