Unit4_final / test_free_gaia.py
Hemil4's picture
Upload folder using huggingface_hub
4e56cc5 verified
"""
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()