Spaces:
Runtime error
Runtime error
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() |