File size: 6,127 Bytes
5b715cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
"""
Test suite for GAIA Agent
Validates imports, tools, model, and agent functionality
"""
import os
import sys

def test_imports():
    """Test 1: Verify all critical imports work"""
    print("\n" + "="*60)
    print("TEST 1: Checking Imports")
    print("="*60)
    
    try:
        import smolagents
        print("βœ… smolagents imported successfully")
    except ImportError as e:
        print(f"❌ smolagents import failed: {e}")
        return False
    
    try:
        import litellm
        print("βœ… litellm imported successfully")
    except ImportError as e:
        print(f"❌ litellm import failed: {e}")
        return False
    
    try:
        import google.generativeai as genai
        print("βœ… google.generativeai imported successfully")
    except ImportError as e:
        print(f"❌ google.generativeai import failed: {e}")
        return False
    
    try:
        from agents import Agent
        print("βœ… Agent class imported successfully")
    except ImportError as e:
        print(f"❌ Agent import failed: {e}")
        return False
    
    try:
        from tool import get_tools
        print("βœ… get_tools imported successfully")
    except ImportError as e:
        print(f"❌ get_tools import failed: {e}")
        return False
    
    try:
        from model import get_model
        print("βœ… get_model imported successfully")
    except ImportError as e:
        print(f"❌ get_model import failed: {e}")
        return False
    
    print("\nβœ… All imports successful!")
    return True


def test_tools():
    """Test 2: Verify tools can be loaded"""
    print("\n" + "="*60)
    print("TEST 2: Checking Tools")
    print("="*60)
    
    try:
        from tool import get_tools
        tools = get_tools()
        print(f"βœ… Loaded {len(tools)} tools")
        
        # List tools
        for i, tool in enumerate(tools, 1):
            tool_name = getattr(tool, 'name', type(tool).__name__)
            print(f"   {i}. {tool_name}")
        
        return True
    except Exception as e:
        print(f"❌ Tools loading failed: {e}")
        import traceback
        traceback.print_exc()
        return False


def test_environment():
    """Test 3: Check environment variables"""
    print("\n" + "="*60)
    print("TEST 3: Checking Environment")
    print("="*60)
    
    gemini_key = os.getenv("GEMINI_API_KEY")
    
    if gemini_key:
        # Mask the key for security
        masked_key = gemini_key[:8] + "..." + gemini_key[-4:] if len(gemini_key) > 12 else "***"
        print(f"βœ… GEMINI_API_KEY configured: {masked_key}")
        return True
    else:
        print("⚠️  GEMINI_API_KEY not configured")
        print("   Set it with: $env:GEMINI_API_KEY=\"your_key_here\" (PowerShell)")
        print("   Or create a .env file with: GEMINI_API_KEY=your_key_here")
        return False


def test_model():
    """Test 4: Verify model can be instantiated"""
    print("\n" + "="*60)
    print("TEST 4: Checking Model")
    print("="*60)
    
    if not os.getenv("GEMINI_API_KEY"):
        print("⚠️  Skipping model test (GEMINI_API_KEY not configured)")
        return False
    
    try:
        from model import get_model
        
        model_id = "gemini/gemini-2.0-flash-exp"
        print(f"Initializing model: {model_id}")
        
        model = get_model("LiteLLMModel", model_id)
        print("βœ… Model instantiated successfully")
        
        # Test simple inference
        print("Testing simple inference...")
        messages = [{"role": "user", "content": "Say 'test successful' and nothing else"}]
        response = model(messages)
        print(f"βœ… Model response: {response.content[:100]}")
        
        return True
    except Exception as e:
        print(f"❌ Model test failed: {e}")
        import traceback
        traceback.print_exc()
        return False


def test_agent():
    """Test 5: Verify agent can be created and used"""
    print("\n" + "="*60)
    print("TEST 5: Checking Agent")
    print("="*60)
    
    if not os.getenv("GEMINI_API_KEY"):
        print("⚠️  Skipping agent test (GEMINI_API_KEY not configured)")
        return False
    
    try:
        from agents import Agent
        from tool import get_tools
        from model import get_model
        
        model_id = "gemini/gemini-2.0-flash-exp"
        print(f"Creating agent with model: {model_id}")
        
        agent = Agent(
            model=get_model("LiteLLMModel", model_id),
            tools=get_tools(),
            verbose=True
        )
        print("βœ… Agent created successfully")
        
        # Test simple question
        print("\nTesting with simple question...")
        question = "What is 2+2? Answer with only the number."
        print(f"Question: {question}")
        
        answer = agent(question)
        print(f"βœ… Agent answer: {answer}")
        
        return True
    except Exception as e:
        print(f"❌ Agent test failed: {e}")
        import traceback
        traceback.print_exc()
        return False


def main():
    """Run all tests"""
    print("\n" + "πŸ”¬" * 30)
    print(" GAIA AGENT TEST SUITE ".center(60, "="))
    print("πŸ”¬" * 30)
    
    results = {
        "Imports": test_imports(),
        "Tools": test_tools(),
        "Environment": test_environment(),
        "Model": test_model(),
        "Agent": test_agent(),
    }
    
    # Summary
    print("\n" + "="*60)
    print("TEST SUMMARY")
    print("="*60)
    
    passed = sum(results.values())
    total = len(results)
    
    for test_name, passed_test in results.items():
        status = "βœ… PASS" if passed_test else "❌ FAIL"
        print(f"{test_name:20s} {status}")
    
    print("="*60)
    print(f"Total: {passed}/{total} tests passed ({passed/total*100:.1f}%)")
    print("="*60)
    
    if passed == total:
        print("\nπŸŽ‰ ALL TESTS PASSED! Ready for deployment!")
        return 0
    else:
        print(f"\n⚠️  {total - passed} test(s) failed. Please fix before deployment.")
        return 1


if __name__ == "__main__":
    sys.exit(main())