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()