|
|
| """
|
| 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:
|
|
|
| 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
|
|
|
|
|
| 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']}")
|
|
|
|
|
| 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}")
|
|
|
|
|
| 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']})")
|
|
|
|
|
| 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()
|
|
|