#!/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()