-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiagnose_project.py
More file actions
120 lines (108 loc) · 4.22 KB
/
diagnose_project.py
File metadata and controls
120 lines (108 loc) · 4.22 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
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
import os
import sys
from pathlib import Path
import mysql.connector
from data.mysql_db import get_db_connection
from langchain_groq import ChatGroq
from utils.config import GROQ_API_KEY
from utils.logger import logger
def diagnose_project():
print("=== Project Diagnosis ===")
cwd = os.getcwd()
print(f"Current working directory: {cwd}")
print("\nsys.path:")
for path in sys.path:
print(f" {path}")
project_root = str(Path(__file__).parent)
print(f"\nProject root: {project_root}")
if project_root not in sys.path:
print(" Adding project root to sys.path")
sys.path.insert(0, project_root)
agents_dir = os.path.join(project_root, "agents")
print(f"\nAgents directory: {agents_dir}")
if os.path.exists(agents_dir):
print(" Agents directory exists")
files = os.listdir(agents_dir)
print(" Files in agents/:")
for f in files:
print(f" {f}")
else:
print(" ERROR: Agents directory does not exist")
files_to_check = [
"agents/__init__.py",
"agents/workflow.py",
"agents/preference_parser.py",
"agents/market_analyst.py",
"agents/strategist.py",
"agents/executor.py",
"app.py",
"data/mysql_db.py",
"utils/config.py",
"utils/logger.py",
"schema.sql"
]
print("\nChecking critical files:")
for f in files_to_check:
path = os.path.join(project_root, f)
print(f" {f}: {'Exists' if os.path.exists(path) else 'Missing'}")
print("\nTesting imports and methods:")
try:
from agents import run_workflow
print(" Imported run_workflow successfully")
except ImportError as e:
print(f" ERROR: Failed to import run_workflow: {str(e)}")
try:
from agents.market_analyst import MarketAnalystAgent
market_analyst = MarketAnalystAgent()
if hasattr(market_analyst, "analyze_stock"):
print(" MarketAnalystAgent.analyze_stock exists")
else:
print(" ERROR: MarketAnalystAgent missing analyze_stock method")
if hasattr(market_analyst, "fetch_financials"):
print(" MarketAnalystAgent.fetch_financials exists")
else:
print(" ERROR: MarketAnalystAgent missing fetch_financials method")
except ImportError as e:
print(f" ERROR: Failed to import MarketAnalystAgent: {str(e)}")
try:
from agents.strategist import StrategistAgent
strategist = StrategistAgent()
if hasattr(strategist, "generate_recommendations"):
print(" StrategistAgent.generate_recommendations exists")
else:
print(" ERROR: StrategistAgent missing generate_recommendations method")
except ImportError as e:
print(f" ERROR: Failed to import StrategistAgent: {str(e)}")
print("\nTesting database connectivity:")
try:
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute("SHOW TABLES LIKE 'stocks'")
if cursor.fetchone():
print(" Stocks table exists")
else:
print(" ERROR: Stocks table missing")
cursor.execute("SHOW TABLES LIKE 'income_statements'")
if cursor.fetchone():
print(" Income_statements table exists")
else:
print(" ERROR: Income_statements table missing")
cursor.execute("SELECT COUNT(*) AS count FROM stocks")
stock_count = cursor.fetchone()[0]
print(f" Stocks table contains {stock_count} records")
cursor.close()
conn.close()
print(" Database connection successful")
except mysql.connector.Error as e:
print(f" ERROR: Database connection failed: {str(e)}")
print("\nTesting Groq API connectivity:")
try:
llm = ChatGroq(model_name="llama-3.1-8b-instant", api_key=GROQ_API_KEY)
response = llm.invoke("Test API connectivity")
print(" Groq API test successful")
logger.info(f"Groq API test response: {response.content[:100]}...")
except Exception as e:
print(f" ERROR: Groq API test failed: {str(e)}")
print("\n=== Diagnosis Complete ===")
if __name__ == "__main__":
diagnose_project()