Spaces:
Sleeping
Sleeping
| import requests | |
| import json | |
| import time | |
| import sys | |
| import io | |
| # Force UTF-8 encoding for standard output | |
| sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') | |
| BASE_URL = "https://youmei295-planning-agent.hf.space" | |
| def test_health_check(): | |
| print("\n--- Testing /health endpoint ---") | |
| url = f"{BASE_URL}/health" | |
| try: | |
| response = requests.get(url, timeout=10) | |
| print(f"Status Code: {response.status_code}") | |
| if response.status_code == 200: | |
| print("[SUCCESS] Health check passed!") | |
| print("Response:", json.dumps(response.json(), indent=2, ensure_ascii=False)) | |
| else: | |
| print("[ERROR] Health check failed!") | |
| print("Response:", response.text) | |
| except requests.exceptions.RequestException as e: | |
| print(f"[ERROR] Connection error: {e}") | |
| def test_chat_fallback(): | |
| print("\n--- Testing /api/plan (Chat/Fallback Intent) ---") | |
| url = f"{BASE_URL}/api/plan" | |
| headers = {"Content-Type": "application/json"} | |
| payload = { | |
| "message": "Xin chào" | |
| } | |
| try: | |
| response = requests.post(url, headers=headers, json=payload, timeout=60) | |
| print(f"Status Code: {response.status_code}") | |
| if response.status_code == 200: | |
| data = response.json() | |
| if data.get("status") == "chat": | |
| print("[SUCCESS] Chat fallback passed!") | |
| print("Agent Reply:", data.get("itinerary_markdown")) | |
| else: | |
| print("[ERROR] Unexpected status returned:", data.get("status")) | |
| else: | |
| print("[ERROR] Request failed!") | |
| print("Response:", response.text) | |
| except requests.exceptions.RequestException as e: | |
| print(f"[ERROR] Connection error: {e}") | |
| def test_trip_planning(): | |
| print("\n--- Testing /api/plan (Trip Planning Intent) ---") | |
| url = f"{BASE_URL}/api/plan" | |
| headers = {"Content-Type": "application/json"} | |
| # A clear query to trigger the planner | |
| payload = { | |
| "message": "Mình muốn đi chơi cuối tuần ở Bình Thạnh, ưu tiên quán cafe yên tĩnh và ăn đồ nướng.", | |
| "start_date": "2024-12-01", | |
| "num_days": 1 | |
| } | |
| try: | |
| print("Waiting for Agent to process (this may take 10-30 seconds)...") | |
| start_time = time.time() | |
| response = requests.post(url, headers=headers, json=payload, timeout=120) | |
| elapsed_time = time.time() - start_time | |
| print(f"Status Code: {response.status_code}") | |
| print(f"Time taken: {elapsed_time:.2f} seconds") | |
| if response.status_code == 200: | |
| data = response.json() | |
| if data.get("status") == "success": | |
| print("[SUCCESS] Trip planning passed!") | |
| print(f"Total Cost: {data.get('total_cost')}") | |
| print(f"Timeline items: {len(data.get('timeline', []))}") | |
| print("\n=== FULL ITINERARY MARKDOWN ===") | |
| print(data.get("itinerary_markdown")) | |
| print("\n=== FULL TIMELINE ===") | |
| print(json.dumps(data.get("timeline"), indent=2, ensure_ascii=False)) | |
| else: | |
| print("[ERROR] Unexpected status returned:", data.get("status")) | |
| print("Response:", json.dumps(data, indent=2, ensure_ascii=False)) | |
| else: | |
| print("[ERROR] Request failed!") | |
| print("Response:", response.text) | |
| except requests.exceptions.RequestException as e: | |
| print(f"[ERROR] Connection error: {e}") | |
| if __name__ == "__main__": | |
| print(f"Testing Agent Endpoint: {BASE_URL}") | |
| test_health_check() | |
| test_chat_fallback() | |
| test_trip_planning() | |
| print("\nDone!") | |