Final_Assignment_Template / test_local.py
Denis Davydov
initial
f9a7c9b
raw
history blame
3.83 kB
#!/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()