File size: 5,092 Bytes
4e56cc5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
"""
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() |