File size: 3,829 Bytes
f9a7c9b |
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 |
#!/usr/bin/env python3
"""
Local testing script for the GAIA agent.
Run this to test the agent before deploying to HF Spaces.
"""
import os
import sys
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Add current directory to path for imports
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from utils import fetch_random_question, analyze_question_type
from agent import smart_agent
def test_question_analysis():
"""Test the question analysis functionality."""
print("π§ͺ Testing question analysis...")
test_questions = [
"What is the current population of Tokyo?",
"Calculate 15 * 23 + 45",
"Analyze the image shown in the document",
"Extract all dates from the provided text file"
]
for question in test_questions:
analysis = analyze_question_type(question)
print(f"Question: {question}")
print(f"Analysis: {analysis}")
print()
def test_tools():
"""Test individual tools."""
print("π§ Testing individual tools...")
# Test calculator
from tools import calculator_tool
calc_result = calculator_tool.func("15 + 27")
print(f"Calculator test: {calc_result}")
# Test web search (if available)
try:
from tools import web_search_tool
search_result = web_search_tool.func("Python programming language")
print(f"Web search test: {search_result[:100]}...")
except Exception as e:
print(f"Web search test failed: {e}")
print()
def test_agent_simple():
"""Test the agent with a simple question."""
print("π€ Testing Smart agent with simple question...")
test_question = "What is 25 + 17?"
try:
result = smart_agent(test_question)
print(f"Question: {test_question}")
print(f"Answer: {result}")
print("β
Simple test passed!")
except Exception as e:
print(f"β Simple test failed: {e}")
print()
def test_agent_with_api():
"""Test the agent with a real GAIA question from the API."""
print("π Testing with real GAIA question from API...")
try:
question_data = fetch_random_question()
if not question_data:
print("β Failed to fetch question from API")
return
task_id = question_data.get("task_id")
question = question_data.get("question")
print(f"Task ID: {task_id}")
print(f"Question: {question}")
# Run the agent
answer = smart_agent(question, task_id)
print(f"Agent Answer: {answer}")
print("β
API test completed!")
except Exception as e:
print(f"β API test failed: {e}")
print()
def check_environment():
"""Check if all required environment variables are set."""
print("π Checking environment...")
required_vars = ["HUGGINGFACE_API_TOKEN"]
missing_vars = []
for var in required_vars:
if not os.getenv(var):
missing_vars.append(var)
else:
print(f"β
{var} is set")
if missing_vars:
print(f"β Missing environment variables: {missing_vars}")
print("Please set these in your .env file or environment")
return False
print("β
All required environment variables are set")
return True
def main():
"""Run all tests."""
print("π Starting GAIA Agent Local Tests")
print("=" * 50)
# Check environment first
if not check_environment():
print("β Environment check failed. Please fix and try again.")
return
print()
# Run tests
# test_question_analysis()
# test_tools()
# test_agent_simple()
test_agent_with_api()
if __name__ == "__main__":
main()
|