|
|
|
""" |
|
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_dotenv() |
|
|
|
|
|
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...") |
|
|
|
|
|
from tools import calculator_tool |
|
calc_result = calculator_tool.func("15 + 27") |
|
print(f"Calculator test: {calc_result}") |
|
|
|
|
|
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}") |
|
|
|
|
|
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) |
|
|
|
|
|
if not check_environment(): |
|
print("β Environment check failed. Please fix and try again.") |
|
return |
|
|
|
print() |
|
|
|
|
|
|
|
|
|
|
|
test_agent_with_api() |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|