File size: 4,004 Bytes
843728a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Test script for GAIA Agent
Run this to verify your agent works before deploying
"""

import os
import sys
from pathlib import Path

# Add current directory to path
sys.path.append(str(Path(__file__).parent))

def test_environment():
    """Test environment variables and dependencies"""
    print("πŸ§ͺ Testing Environment Setup")
    print("-" * 40)
    
    # Check environment variables
    serper_key = os.getenv("SERPER_API_KEY")
    hf_token = os.getenv("HUGGINGFACE_INFERENCE_TOKEN")
    
    print(f"SERPER_API_KEY: {'βœ… Found' if serper_key else '❌ Missing'}")
    print(f"HF_TOKEN: {'βœ… Found' if hf_token else '❌ Missing'}")
    
    # Test imports
    try:
        import gradio as gr
        print("Gradio: βœ… Imported")
    except ImportError as e:
        print(f"Gradio: ❌ Import failed - {e}")
    
    try:
        import smolagents
        print("SmolagentS: βœ… Imported")
    except ImportError as e:
        print(f"SmolagentS: ❌ Import failed - {e}")
    
    try:
        import pandas as pd
        print("Pandas: βœ… Imported")
    except ImportError as e:
        print(f"Pandas: ❌ Import failed - {e}")
    
    try:
        import requests
        print("Requests: βœ… Imported")
    except ImportError as e:
        print(f"Requests: ❌ Import failed - {e}")

def test_agent_basic():
    """Test basic agent functionality"""
    print("\nπŸ€– Testing Agent Initialization")
    print("-" * 40)
    
    try:
        # Import the agent
        from app import GAIAAgent
        
        # Initialize agent
        agent = GAIAAgent()
        
        if agent.agent is None:
            print("❌ Agent initialization failed")
            return False
        
        print("βœ… Agent initialized successfully")
        
        # Test with simple questions
        test_questions = [
            "What is 2 + 2?",
            "What is the capital of France?",
            "Calculate the square root of 16"
        ]
        
        for i, question in enumerate(test_questions, 1):
            print(f"\nπŸ“ Test Question {i}: {question}")
            try:
                answer = agent(question)
                print(f"βœ… Answer: {answer[:100]}...")
            except Exception as e:
                print(f"❌ Error: {e}")
        
        return True
        
    except Exception as e:
        print(f"❌ Agent test failed: {e}")
        return False

def test_tools():
    """Test individual tools"""
    print("\nπŸ› οΈ Testing Individual Tools")
    print("-" * 40)
    
    try:
        from app import SerperSearchTool, MathCalculatorTool
        
        # Test search tool
        search_tool = SerperSearchTool()
        try:
            result = search_tool("Python programming")
            print(f"βœ… Search Tool: {result[:100]}...")
        except Exception as e:
            print(f"❌ Search Tool Error: {e}")
        
        # Test math tool
        math_tool = MathCalculatorTool()
        try:
            result = math_tool("2 + 2")
            print(f"βœ… Math Tool: {result}")
        except Exception as e:
            print(f"❌ Math Tool Error: {e}")
        
        # Test math tool with complex expression
        try:
            result = math_tool("sqrt(16) + 3 * 2")
            print(f"βœ… Math Complex: {result}")
        except Exception as e:
            print(f"❌ Math Complex Error: {e}")
            
    except Exception as e:
        print(f"❌ Tools test failed: {e}")

def main():
    """Run all tests"""
    print("πŸš€ GAIA Agent Test Suite")
    print("=" * 50)
    
    # Test environment
    test_environment()
    
    # Test tools
    test_tools()
    
    # Test agent
    success = test_agent_basic()
    
    print("\n" + "=" * 50)
    if success:
        print("βœ… All tests passed! Your agent is ready for deployment.")
    else:
        print("❌ Some tests failed. Please check the errors above.")
    print("=" * 50)

if __name__ == "__main__":
    main()