Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,7 @@ from tools.report_tool import ReportTool
|
|
| 10 |
from utils.tracing import Tracer
|
| 11 |
from utils.config import AppConfig
|
| 12 |
from tools.ts_forecast_tool import TimeseriesForecastTool
|
|
|
|
| 13 |
|
| 14 |
# Optional tiny CPU LLM for planning (can be disabled by not setting ORCHESTRATOR_MODEL)
|
| 15 |
llm = None
|
|
@@ -78,16 +79,27 @@ def run_agent(message: str, hitl_decision: str = "Approve", reviewer_note: str =
|
|
| 78 |
explain_imgs = {}
|
| 79 |
artifacts = {}
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
if "sql" in plan["steps"]:
|
| 82 |
sql_df = sql_tool.run(message)
|
| 83 |
artifacts["sql_rows"] = int(len(sql_df)) if isinstance(sql_df, pd.DataFrame) else 0
|
| 84 |
|
| 85 |
if "predict" in plan["steps"]:
|
| 86 |
-
|
| 87 |
|
| 88 |
if "explain" in plan["steps"]:
|
| 89 |
explain_imgs = explain_tool.run(predict_df or sql_df)
|
| 90 |
|
|
|
|
|
|
|
|
|
|
| 91 |
report_link = None
|
| 92 |
if "report" in plan["steps"]:
|
| 93 |
report_link = report_tool.render_and_save(
|
|
|
|
| 10 |
from utils.tracing import Tracer
|
| 11 |
from utils.config import AppConfig
|
| 12 |
from tools.ts_forecast_tool import TimeseriesForecastTool
|
| 13 |
+
from tools.ts_preprocess import build_timeseries
|
| 14 |
|
| 15 |
# Optional tiny CPU LLM for planning (can be disabled by not setting ORCHESTRATOR_MODEL)
|
| 16 |
llm = None
|
|
|
|
| 79 |
explain_imgs = {}
|
| 80 |
artifacts = {}
|
| 81 |
|
| 82 |
+
if "sql" in plan["steps"]:
|
| 83 |
+
sql_df = sql_tool.run(message)
|
| 84 |
+
# 👉 Build the model-friendly time series (monthly)
|
| 85 |
+
try:
|
| 86 |
+
ts_df = build_timeseries(sql_df)
|
| 87 |
+
except Exception:
|
| 88 |
+
ts_df = None
|
| 89 |
+
|
| 90 |
if "sql" in plan["steps"]:
|
| 91 |
sql_df = sql_tool.run(message)
|
| 92 |
artifacts["sql_rows"] = int(len(sql_df)) if isinstance(sql_df, pd.DataFrame) else 0
|
| 93 |
|
| 94 |
if "predict" in plan["steps"]:
|
| 95 |
+
predict_df = predict_tool.run(sql_df)
|
| 96 |
|
| 97 |
if "explain" in plan["steps"]:
|
| 98 |
explain_imgs = explain_tool.run(predict_df or sql_df)
|
| 99 |
|
| 100 |
+
if "forecast" in plan["steps"] and ts_df is not None:
|
| 101 |
+
fc = ts_tool.zeroshot_forecast(ts_df[["timestamp","portfolio_value","interest_rate"]].dropna())
|
| 102 |
+
|
| 103 |
report_link = None
|
| 104 |
if "report" in plan["steps"]:
|
| 105 |
report_link = report_tool.render_and_save(
|