add tests
This commit is contained in:
parent
964c514424
commit
b862c3b7f9
|
|
@ -7,3 +7,6 @@ eval_results/
|
|||
eval_data/
|
||||
*.egg-info/
|
||||
.env
|
||||
|
||||
results
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
"""
|
||||
TradingAgents Test Suite
|
||||
"""
|
||||
|
||||
__version__ = "0.1.0"
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script to demonstrate the new environment loading functionality
|
||||
"""
|
||||
|
||||
from tradingagents.utils.env_loader import load_environment_variables, print_environment_status, get_llm_config
|
||||
|
||||
def test_environment_loading():
|
||||
"""Test the environment loading functionality"""
|
||||
|
||||
print("🧪 Testing Environment Loading")
|
||||
print("=" * 40)
|
||||
|
||||
# Test environment loading
|
||||
env_info = load_environment_variables()
|
||||
|
||||
print(f"\n📁 Environment file: {env_info['env_file_path']}")
|
||||
print(f"🔑 FinnHub available: {env_info['validation']['finnhub_available']}")
|
||||
print(f"🤖 LLM providers: {env_info['validation']['llm_providers_available']}")
|
||||
print(f"✅ All required available: {env_info['validation']['all_required_available']}")
|
||||
|
||||
if env_info['validation']['warnings']:
|
||||
print("\n⚠️ Warnings:")
|
||||
for warning in env_info['validation']['warnings']:
|
||||
print(f" • {warning}")
|
||||
|
||||
return env_info
|
||||
|
||||
def test_provider_configs():
|
||||
"""Test provider configuration retrieval"""
|
||||
|
||||
print("\n🔧 Testing Provider Configurations")
|
||||
print("=" * 40)
|
||||
|
||||
providers = ["openai", "google", "anthropic"]
|
||||
|
||||
for provider in providers:
|
||||
config = get_llm_config(provider)
|
||||
print(f"\n📋 {provider.upper()} Configuration:")
|
||||
print(f" Backend URL: {config.get('backend_url', 'Not needed')}")
|
||||
print(f" Embedding Model: {config.get('embedding_model', 'Unknown')}")
|
||||
print(f" API Key Env: {config.get('api_key_env', 'Unknown')}")
|
||||
|
||||
quick_models = config.get('supported_models', {}).get('quick_think', [])
|
||||
deep_models = config.get('supported_models', {}).get('deep_think', [])
|
||||
|
||||
print(f" Quick Think Models: {len(quick_models)} available")
|
||||
print(f" Deep Think Models: {len(deep_models)} available")
|
||||
|
||||
def test_gemini_specific():
|
||||
"""Test Gemini-specific configuration"""
|
||||
|
||||
print("\n🤖 Testing Gemini Configuration")
|
||||
print("=" * 40)
|
||||
|
||||
google_config = get_llm_config("google")
|
||||
|
||||
print(f"Backend URL: {google_config.get('backend_url')}")
|
||||
print(f"Embedding Model: {google_config.get('embedding_model')}")
|
||||
|
||||
if google_config.get('backend_url') is None:
|
||||
print("✅ Correct: Google doesn't need backend_url")
|
||||
else:
|
||||
print("❌ Incorrect: Google should not have backend_url")
|
||||
|
||||
# Test model availability
|
||||
quick_models = google_config.get('supported_models', {}).get('quick_think', [])
|
||||
deep_models = google_config.get('supported_models', {}).get('deep_think', [])
|
||||
|
||||
print(f"\nAvailable Gemini Models:")
|
||||
print(f" Quick Think: {quick_models}")
|
||||
print(f" Deep Think: {deep_models}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("🚀 TradingAgents Environment Testing")
|
||||
print("=" * 50)
|
||||
|
||||
# Test environment loading
|
||||
env_info = test_environment_loading()
|
||||
|
||||
# Test provider configurations
|
||||
test_provider_configs()
|
||||
|
||||
# Test Gemini-specific configuration
|
||||
test_gemini_specific()
|
||||
|
||||
# Show full environment status
|
||||
print("\n" + "=" * 50)
|
||||
print_environment_status()
|
||||
|
||||
print("\n✅ Environment testing completed!")
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script to verify Gemini integration with TradingAgents
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add the project root to the Python path
|
||||
project_root = Path(__file__).parent.parent
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
from tradingagents.graph.trading_graph import TradingAgentsGraph
|
||||
from tradingagents.default_config import DEFAULT_CONFIG
|
||||
|
||||
def test_gemini_integration():
|
||||
"""Test the Gemini integration"""
|
||||
|
||||
# Check if Google API key is available
|
||||
if not os.getenv("GOOGLE_API_KEY"):
|
||||
print("❌ GOOGLE_API_KEY environment variable not set")
|
||||
print("Please set it with: export GOOGLE_API_KEY=your_key_here")
|
||||
return False
|
||||
|
||||
# Create a config for Gemini
|
||||
config = DEFAULT_CONFIG.copy()
|
||||
config["llm_provider"] = "google"
|
||||
config["backend_url"] = "https://generativelanguage.googleapis.com/v1"
|
||||
config["deep_think_llm"] = "gemini-2.0-flash"
|
||||
config["quick_think_llm"] = "gemini-2.0-flash"
|
||||
config["max_debate_rounds"] = 1
|
||||
config["online_tools"] = True
|
||||
|
||||
try:
|
||||
print("🚀 Testing Gemini integration...")
|
||||
|
||||
# Initialize the graph with Gemini
|
||||
graph = TradingAgentsGraph(
|
||||
selected_analysts=["market", "news"], # Use fewer analysts for testing
|
||||
debug=True,
|
||||
config=config
|
||||
)
|
||||
|
||||
print("✅ TradingAgentsGraph initialized successfully with Gemini")
|
||||
|
||||
# Test a simple propagation
|
||||
print("🔄 Testing propagation with SPY...")
|
||||
_, decision = graph.propagate("SPY", "2024-12-01")
|
||||
|
||||
print(f"✅ Propagation completed successfully!")
|
||||
print(f"📊 Final decision: {decision}")
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error during Gemini integration test: {str(e)}")
|
||||
return False
|
||||
|
||||
def test_memory_system():
|
||||
"""Test the memory system with Gemini embeddings"""
|
||||
|
||||
if not os.getenv("GOOGLE_API_KEY"):
|
||||
print("❌ GOOGLE_API_KEY environment variable not set")
|
||||
return False
|
||||
|
||||
try:
|
||||
from tradingagents.agents.utils.memory import FinancialSituationMemory
|
||||
|
||||
config = {
|
||||
"llm_provider": "google",
|
||||
"backend_url": "https://generativelanguage.googleapis.com/v1"
|
||||
}
|
||||
|
||||
print("🧠 Testing memory system with Gemini embeddings...")
|
||||
|
||||
memory = FinancialSituationMemory("test_memory", config)
|
||||
|
||||
# Test adding situations
|
||||
test_data = [
|
||||
("High inflation with rising interest rates", "Consider defensive sectors"),
|
||||
("Tech sector volatility increasing", "Reduce exposure to growth stocks")
|
||||
]
|
||||
|
||||
memory.add_situations(test_data)
|
||||
print("✅ Memory system working with Gemini embeddings")
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error in memory system test: {str(e)}")
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("🧪 Testing TradingAgents Gemini Integration")
|
||||
print("=" * 50)
|
||||
|
||||
# Test memory system first
|
||||
memory_success = test_memory_system()
|
||||
|
||||
if memory_success:
|
||||
# Test full integration
|
||||
integration_success = test_gemini_integration()
|
||||
|
||||
if integration_success:
|
||||
print("\n🎉 All Gemini integration tests passed!")
|
||||
else:
|
||||
print("\n❌ Gemini integration test failed")
|
||||
else:
|
||||
print("\n❌ Memory system test failed")
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script to verify OpenAI integration with TradingAgents
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add the project root to the Python path
|
||||
project_root = Path(__file__).parent.parent
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
from tradingagents.graph.trading_graph import TradingAgentsGraph
|
||||
from tradingagents.default_config import DEFAULT_CONFIG
|
||||
|
||||
def test_openai_integration():
|
||||
"""Test the OpenAI integration"""
|
||||
|
||||
# Check if OpenAI API key is available
|
||||
if not os.getenv("OPENAI_API_KEY"):
|
||||
print("❌ OPENAI_API_KEY environment variable not set")
|
||||
print("Please set it with: export OPENAI_API_KEY=your_key_here")
|
||||
return False
|
||||
|
||||
# Create a config for OpenAI
|
||||
config = DEFAULT_CONFIG.copy()
|
||||
config["llm_provider"] = "openai"
|
||||
config["backend_url"] = "https://api.openai.com/v1"
|
||||
config["deep_think_llm"] = "gpt-4o-mini"
|
||||
config["quick_think_llm"] = "gpt-4o-mini"
|
||||
config["max_debate_rounds"] = 1
|
||||
config["online_tools"] = True
|
||||
|
||||
try:
|
||||
print("🚀 Testing OpenAI integration...")
|
||||
|
||||
# Initialize the graph with OpenAI
|
||||
graph = TradingAgentsGraph(
|
||||
selected_analysts=["market", "news"], # Use fewer analysts for testing
|
||||
debug=True,
|
||||
config=config
|
||||
)
|
||||
|
||||
print("✅ TradingAgentsGraph initialized successfully with OpenAI")
|
||||
|
||||
# Test a simple propagation
|
||||
print("🔄 Testing propagation with SPY...")
|
||||
_, decision = graph.propagate("SPY", "2024-12-01")
|
||||
|
||||
print(f"✅ Propagation completed successfully!")
|
||||
print(f"📊 Final decision: {decision}")
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error during OpenAI integration test: {str(e)}")
|
||||
return False
|
||||
|
||||
def test_memory_system():
|
||||
"""Test the memory system with OpenAI embeddings"""
|
||||
|
||||
if not os.getenv("OPENAI_API_KEY"):
|
||||
print("❌ OPENAI_API_KEY environment variable not set")
|
||||
return False
|
||||
|
||||
try:
|
||||
from tradingagents.agents.utils.memory import FinancialSituationMemory
|
||||
|
||||
config = {
|
||||
"llm_provider": "openai",
|
||||
"backend_url": "https://api.openai.com/v1"
|
||||
}
|
||||
|
||||
print("🧠 Testing memory system with OpenAI embeddings...")
|
||||
|
||||
memory = FinancialSituationMemory("test_memory", config)
|
||||
|
||||
# Test adding situations
|
||||
test_data = [
|
||||
("High inflation with rising interest rates", "Consider defensive sectors"),
|
||||
("Tech sector volatility increasing", "Reduce exposure to growth stocks")
|
||||
]
|
||||
|
||||
memory.add_situations(test_data)
|
||||
print("✅ Memory system working with OpenAI embeddings")
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error in memory system test: {str(e)}")
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("🧪 Testing TradingAgents OpenAI Integration")
|
||||
print("=" * 50)
|
||||
|
||||
# Test memory system first
|
||||
memory_success = test_memory_system()
|
||||
|
||||
if memory_success:
|
||||
# Test full integration
|
||||
integration_success = test_openai_integration()
|
||||
|
||||
if integration_success:
|
||||
print("\n🎉 All OpenAI integration tests passed!")
|
||||
else:
|
||||
print("\n❌ OpenAI integration test failed")
|
||||
else:
|
||||
print("\n❌ Memory system test failed")
|
||||
Loading…
Reference in New Issue