Spaces:
Sleeping
Sleeping
File size: 4,946 Bytes
1d0ce3b |
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 147 148 149 150 151 152 |
#!/usr/bin/env python3
"""
Test script for the enhanced GAIA agent
"""
import os
import sys
from dotenv import load_dotenv
# Add current directory to path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
try:
from langgraph_new import graph, answer_gaia_question, get_random_gaia_question
print("β
Successfully imported enhanced GAIA agent")
except ImportError as e:
print(f"β Import error: {e}")
sys.exit(1)
def test_basic_functionality():
"""Test basic agent functionality"""
print("\nπ§ Testing basic functionality...")
test_cases = [
("What is 2 + 2?", "4"),
("What is the capital of France?", "Paris"),
("List these items alphabetically: zebra, apple, banana", "apple, banana, zebra"),
]
for question, expected in test_cases:
try:
answer = answer_gaia_question(question)
print(f"Q: {question}")
print(f"A: {answer}")
print(f"Expected: {expected}")
print(f"Match: {'β
' if expected.lower() in answer.lower() else 'β'}")
print("-" * 50)
except Exception as e:
print(f"β Error answering '{question}': {e}")
def test_file_analysis():
"""Test file analysis capabilities"""
print("\nπ Testing file analysis...")
# Test Excel file if it exists
if os.path.exists("test_sales.xlsx"):
try:
question = "Given the Excel file at test_sales.xlsx, what is the structure of the data?"
answer = answer_gaia_question(question)
print(f"Q: {question}")
print(f"A: {answer}")
except Exception as e:
print(f"β Excel test error: {e}")
else:
print("β οΈ test_sales.xlsx not found, skipping Excel test")
# Test audio file if it exists
if os.path.exists("test.wav"):
try:
question = "What does the speaker say in the audio file test.wav?"
answer = answer_gaia_question(question)
print(f"Q: {question}")
print(f"A: {answer}")
except Exception as e:
print(f"β Audio test error: {e}")
else:
print("β οΈ test.wav not found, skipping audio test")
def test_youtube_capability():
"""Test YouTube transcript capability"""
print("\nπ₯ Testing YouTube capability...")
try:
# Test with a known working video
question = """Examine the video at https://www.youtube.com/watch?v=1htKBjuUWec. What does Teal'c say in response to the question "Isn't that hot?" """
answer = answer_gaia_question(question)
print(f"Q: {question}")
print(f"A: {answer}")
except Exception as e:
print(f"β YouTube test error: {e}")
def test_web_search():
"""Test web search capabilities"""
print("\nπ Testing web search...")
try:
question = "Who is the current president of France in 2025?"
answer = answer_gaia_question(question)
print(f"Q: {question}")
print(f"A: {answer}")
except Exception as e:
print(f"β Web search test error: {e}")
def test_real_gaia_question():
"""Test with a real GAIA question from the API"""
print("\nπ― Testing with real GAIA question...")
try:
question_data = get_random_gaia_question()
if question_data:
question = question_data.get('question', '')
task_id = question_data.get('task_id', 'Unknown')
print(f"Task ID: {task_id}")
print(f"Question: {question}")
answer = answer_gaia_question(question)
print(f"Agent Answer: {answer}")
return {"task_id": task_id, "question": question, "answer": answer}
else:
print("β οΈ Could not fetch random GAIA question")
return None
except Exception as e:
print(f"β Real GAIA question test error: {e}")
return None
def main():
"""Main test runner"""
load_dotenv()
print("π Starting GAIA Agent Tests")
print("=" * 60)
# Check environment variables
required_vars = ["OPENAI_API_KEY", "TAVILY_API_KEY"]
missing_vars = [var for var in required_vars if not os.getenv(var)]
if missing_vars:
print(f"β Missing environment variables: {missing_vars}")
print("Please set these in your .env file")
return
# Run tests
test_basic_functionality()
test_file_analysis()
test_web_search()
test_youtube_capability()
# Test with real GAIA question
gaia_result = test_real_gaia_question()
print("\n" + "=" * 60)
print("π Test suite completed!")
if gaia_result:
print("\nπ Sample GAIA Result:")
print(f"Task ID: {gaia_result['task_id']}")
print(f"Answer: {gaia_result['answer']}")
if __name__ == "__main__":
main()
|