-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest_gemini_connection.py
More file actions
68 lines (55 loc) · 2.27 KB
/
test_gemini_connection.py
File metadata and controls
68 lines (55 loc) · 2.27 KB
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
import os
import logging
import pandas as pd
from dotenv import load_dotenv
from src.agent.langchain_planner import generate_strategy_proposals
# Setup logging to see errors
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("src.agent.langchain_planner")
logger.setLevel(logging.DEBUG)
def test_gemini():
load_dotenv()
api_key = os.getenv("GOOGLE_API_KEY")
if not api_key:
print("❌ GOOGLE_API_KEY not found in environment variables.")
return
print(f"✅ Found API Key: {api_key[:5]}...{api_key[-5:]}")
print("Attempting to connect to Gemini-2.5-flash...")
# Dummy data
regime_data = "Bull Market"
features_df = pd.DataFrame([{
'close': 100,
'volume': 1000000,
'rsi': 60,
'macd': 0.5
}])
baseline_stats = pd.Series({'sharpe': 1.5})
strategy_types = ["momentum"]
available_assets = ["SPY"]
try:
proposals = generate_strategy_proposals(
regime_data=regime_data,
features_df=features_df,
baseline_stats=baseline_stats,
strategy_types=strategy_types,
available_assets=available_assets,
num_proposals=1
)
if proposals:
print("\n✅ Success! Received proposal:")
print(proposals[0])
# Check if it looks like a random fallback or real LLM response
rationale = proposals[0].get('rationale', '')
print(f"\nRationale provided: {rationale}")
# In langchain_planner.py, the fallback rationale is a formatted string starting with "This {strategy_type} strategy..."
# The LLM rationale comes from response.get("reasoning", "Generated by AI")
if "Generated by AI" in rationale or "reasoning" in str(proposals[0]) or not rationale.startswith("This momentum strategy is designed"):
print("\n🎉 This looks like an AI generated response.")
else:
print("\n⚠️ This looks like a FALLBACK response. Check the logs above for connection errors.")
else:
print("❌ No proposals returned.")
except Exception as e:
print(f"❌ Error running test: {e}")
if __name__ == "__main__":
test_gemini()