Spaces:
Runtime error
Runtime error
#!/usr/bin/env python3 | |
""" | |
π GAIA Agent Diagnostic Test | |
Quick test to diagnose why the agent isn't answering questions | |
""" | |
import os | |
import sys | |
from gaia_system import BasicAgent, EnhancedMultiModelGAIASystem | |
def test_basic_agent(): | |
"""Test the BasicAgent with simple questions""" | |
print("π§ͺ Testing BasicAgent...") | |
try: | |
# Initialize agent | |
agent = BasicAgent() | |
print("β Agent initialized successfully") | |
# Test simple questions | |
test_questions = [ | |
"What is 2 + 2?", | |
"What is the capital of France?", | |
"How many days are in a week?", | |
"What color is the sky?" | |
] | |
for i, question in enumerate(test_questions, 1): | |
print(f"\nπ Test {i}: {question}") | |
try: | |
response = agent(question) | |
print(f"π€ Response: '{response}'") | |
print(f"π Length: {len(response)} characters") | |
if not response or response.strip() == "": | |
print("β Empty response!") | |
elif "Unable to" in response or "Error" in response: | |
print("β οΈ Error response detected") | |
else: | |
print("β Got non-empty response") | |
except Exception as e: | |
print(f"β Error: {e}") | |
except Exception as e: | |
print(f"β Failed to initialize agent: {e}") | |
return False | |
return True | |
def test_enhanced_system(): | |
"""Test the EnhancedMultiModelGAIASystem directly""" | |
print("\nπ§ͺ Testing EnhancedMultiModelGAIASystem...") | |
try: | |
# Test with HF token if available | |
hf_token = os.getenv('HF_TOKEN') | |
if hf_token: | |
print(f"β Found HF_TOKEN: {hf_token[:10]}...") | |
else: | |
print("β οΈ No HF_TOKEN found - using fallback mode") | |
system = EnhancedMultiModelGAIASystem(hf_token=hf_token) | |
print("β Enhanced system initialized") | |
# Test simple query | |
question = "What is 5 + 3?" | |
print(f"\nπ Testing: {question}") | |
response = system.query_with_tools(question) | |
print(f"π€ Raw response: '{response}'") | |
# Test fallback | |
fallback = system._fallback_response(question) | |
print(f"π‘οΈ Fallback response: '{fallback}'") | |
# Test answer extraction | |
if response: | |
extracted = system._extract_final_answer(response) | |
print(f"β¨ Extracted answer: '{extracted}'") | |
return True | |
except Exception as e: | |
print(f"β Enhanced system error: {e}") | |
import traceback | |
traceback.print_exc() | |
return False | |
def test_model_availability(): | |
"""Test which AI models are available""" | |
print("\nπ Testing model availability...") | |
try: | |
system = EnhancedMultiModelGAIASystem() | |
print(f"π Available models: {len(system.clients)}") | |
for name, client_info in system.clients.items(): | |
provider = client_info.get('provider', 'Unknown') | |
priority = client_info.get('priority', 999) | |
print(f" - {name} (Priority: {priority}, Provider: {provider})") | |
if system.model_priority: | |
print(f"π― Top priority model: {system.model_priority[0]}") | |
else: | |
print("β No models in priority list!") | |
return True | |
except Exception as e: | |
print(f"β Model availability error: {e}") | |
return False | |
def main(): | |
"""Run all diagnostic tests""" | |
print("π GAIA Agent Diagnostic Tests\n") | |
# Test basic functionality | |
test1 = test_basic_agent() | |
test2 = test_enhanced_system() | |
test3 = test_model_availability() | |
print("\nπ Test Summary:") | |
print(f" BasicAgent: {'β PASS' if test1 else 'β FAIL'}") | |
print(f" Enhanced System: {'β PASS' if test2 else 'β FAIL'}") | |
print(f" Model Availability: {'β PASS' if test3 else 'β FAIL'}") | |
if not any([test1, test2, test3]): | |
print("\nβ All tests failed! Check dependencies and configuration.") | |
return False | |
elif not test1: | |
print("\nβ οΈ BasicAgent failed - this is the issue for GAIA submissions!") | |
return False | |
else: | |
print("\nβ Core functionality working - issue might be elsewhere") | |
return True | |
if __name__ == "__main__": | |
success = main() | |
sys.exit(0 if success else 1) |