|
|
""" |
|
|
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: |
|
|
|
|
|
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'])}") |
|
|
|
|
|
|
|
|
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_question = "What is 15 + 27?" |
|
|
result = agent.solve_question(test_question, "test_001", "1") |
|
|
print(f"β
Agent working - Test answer: {result['model_answer']}") |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
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() |