""" Test script for Free GAIA Agent Run this to verify everything works before processing the full dataset """ import sys import requests import wikipedia as wiki def test_internet_connection(): """Test internet connectivity""" print("๐ŸŒ Testing internet connection...") try: response = requests.get("https://www.google.com", timeout=5) print("โœ… Internet connection working") return True except Exception as e: print(f"โŒ Internet connection failed: {e}") return False def test_duckduckgo_api(): """Test DuckDuckGo API""" print("๐Ÿฆ† Testing DuckDuckGo API...") try: response = requests.get("https://api.duckduckgo.com/", params={ "q": "capital of France", "format": "json" }, timeout=10) if response.status_code == 200: data = response.json() print("โœ… DuckDuckGo API working") if data.get("Answer"): print(f" Sample result: {data['Answer']}") return True else: print(f"โš ๏ธ DuckDuckGo API returned status {response.status_code}") return False except Exception as e: print(f"โŒ DuckDuckGo API failed: {e}") return False def test_wikipedia_api(): """Test Wikipedia API""" print("๐Ÿ“š Testing Wikipedia API...") try: # Search for a page results = wiki.search("Paris", results=1) if results: page = wiki.page(results[0]) print("โœ… Wikipedia API working") print(f" Sample result: {page.title} - {page.content[:100]}...") return True else: print("โš ๏ธ Wikipedia search returned no results") return False except Exception as e: print(f"โŒ Wikipedia API failed: {e}") return False def test_gaia_dataset(): """Test GAIA dataset access""" print("๐Ÿ“Š Testing GAIA dataset access...") try: from datasets import load_dataset dataset = load_dataset("gaia-benchmark/GAIA", "2023_all") print("โœ… GAIA dataset access successful") print(f" Validation questions: {len(dataset['validation'])}") print(f" Test questions: {len(dataset['test'])}") # Show sample question sample = dataset["validation"][0] print(f" Sample question: {sample['Question'][:100]}...") return True except Exception as e: print(f"โŒ GAIA dataset access failed: {e}") print("๐Ÿ’ก You may need to request access at:") print(" https://huggingface.co/datasets/gaia-benchmark/GAIA") return False def test_free_agent(): """Test the free agent with a simple question""" print("๐Ÿค– Testing Free GAIA Agent...") try: from free_gaia_agent import FreeGAIAAgent agent = FreeGAIAAgent() # Test simple math question test_question = "What is 15 + 27?" result = agent.solve_question(test_question, "test_001", "1") print(f"โœ… Agent working - Test answer: {result['model_answer']}") # Test capital question test_question2 = "What is the capital of France?" result2 = agent.solve_question(test_question2, "test_002", "1") print(f"โœ… Agent working - Capital answer: {result2['model_answer']}") return True except Exception as e: print(f"โŒ Agent test failed: {e}") return False def main(): """Run all tests""" print("๐Ÿงช Free GAIA Agent Pre-flight Tests") print("=" * 40) tests = [ ("Internet Connection", test_internet_connection), ("DuckDuckGo API", test_duckduckgo_api), ("Wikipedia API", test_wikipedia_api), ("GAIA Dataset", test_gaia_dataset), ("Free Agent", test_free_agent) ] results = [] for test_name, test_func in tests: print(f"\n๐Ÿ” {test_name}") print("-" * 20) try: result = test_func() results.append(result) except Exception as e: print(f"โŒ Test failed with exception: {e}") results.append(False) # Summary print("\n" + "=" * 40) print("๐Ÿ“Š TEST SUMMARY") print("=" * 40) passed = sum(results) total = len(results) for i, (test_name, _) in enumerate(tests): status = "โœ… PASS" if results[i] else "โŒ FAIL" print(f"{test_name:20} {status}") print("-" * 40) print(f"Total: {passed}/{total} tests passed") if passed == total: print("\n๐ŸŽ‰ All tests passed! Ready to run Free GAIA Agent!") print("๐Ÿ“‹ Next step: python3 free_gaia_agent.py") else: print(f"\nโš ๏ธ {total - passed} test(s) failed. Please fix issues before proceeding.") print("\n๐Ÿ’ก Common issues:") print(" - No internet connection") print(" - GAIA dataset access not granted") print(" - Missing Python packages") if __name__ == "__main__": main()