From 2e37bc117d5e5c930ae0e49ca326f6d923851a3e Mon Sep 17 00:00:00 2001 From: SharkQuant Date: Sat, 11 Apr 2026 22:51:22 -0400 Subject: [PATCH] migrate off Railway, update Dockerfile and LLM clients --- .gitignore | 1 + Dockerfile | 2 +- app.py | 24 ++++++++++++++++++++++ main.py | 6 ++++-- railway.toml | 8 -------- tradingagents/llm_clients/openai_client.py | 3 +++ 6 files changed, 33 insertions(+), 11 deletions(-) delete mode 100644 railway.toml diff --git a/.gitignore b/.gitignore index d0cf1547..94182b43 100644 --- a/.gitignore +++ b/.gitignore @@ -218,3 +218,4 @@ __marimo__/ # Cache **/data_cache/ eval_results/ +.env.railway diff --git a/Dockerfile b/Dockerfile index b67c6d8a..706e15c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ WORKDIR /app # System deps for building Python packages RUN apt-get update && apt-get install -y --no-install-recommends \ - gcc g++ && \ + gcc g++ curl && \ rm -rf /var/lib/apt/lists/* COPY requirements.txt . diff --git a/app.py b/app.py index 7a14ce63..1ac90b93 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,9 @@ """FastAPI SSE backend for the structured equity ranking engine.""" +from pathlib import Path +from dotenv import load_dotenv +load_dotenv(Path(__file__).parent / ".env") + import logging import os import re @@ -466,3 +470,23 @@ async def stream_analysis(analysis_id: str, last_event: int = 0): @app.get("/health") async def health(): return {"status": "ok", "engine": "structured_pipeline"} + + +@app.get("/api/status") +async def get_status(): + """Structured pipeline status — no auth required.""" + from datetime import datetime + active_count = len(analyses) + return { + "service": "structured-pipeline", + "engine": "TradingAgents", + "active_analyses": active_count, + "analyses": {k: {"created": v["created"], "done": v["done"]} for k, v in analyses.items()}, + "pid": __import__("os").getpid(), + "uptime": time.time() - __import__("os").getpid(), + } + + +@app.get("/api/health") +async def api_health(): + return {"status": "ok", "service": "structured-pipeline"} diff --git a/main.py b/main.py index 26cab658..cd00d6f2 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,8 @@ from tradingagents.graph.trading_graph import TradingAgentsGraph from tradingagents.default_config import DEFAULT_CONFIG +import os + from dotenv import load_dotenv # Load environment variables from .env file @@ -8,8 +10,8 @@ load_dotenv() # Create a custom config config = DEFAULT_CONFIG.copy() -config["deep_think_llm"] = "gpt-5-mini" # Use a different model -config["quick_think_llm"] = "gpt-5-mini" # Use a different model +config["deep_think_llm"] = os.environ.get("DEEP_THINK_LLM", "gpt-5-mini") +config["quick_think_llm"] = os.environ.get("QUICK_THINK_LLM", "gpt-5-mini") config["max_debate_rounds"] = 1 # Increase debate rounds # Configure data vendors (default uses yfinance, no extra API keys needed) diff --git a/railway.toml b/railway.toml deleted file mode 100644 index 676581a2..00000000 --- a/railway.toml +++ /dev/null @@ -1,8 +0,0 @@ -[build] -builder = "DOCKERFILE" -dockerfilePath = "Dockerfile" - -[deploy] -healthcheckPath = "/health" -restartPolicyType = "ON_FAILURE" -restartPolicyMaxRetries = 3 diff --git a/tradingagents/llm_clients/openai_client.py b/tradingagents/llm_clients/openai_client.py index 7011895f..96ceb66b 100644 --- a/tradingagents/llm_clients/openai_client.py +++ b/tradingagents/llm_clients/openai_client.py @@ -60,6 +60,9 @@ class OpenAIClient(BaseLLMClient): llm_kwargs["api_key"] = "ollama" # Ollama doesn't require auth elif self.base_url: llm_kwargs["base_url"] = self.base_url + api_key = os.environ.get("OPENAI_API_KEY") + if api_key: + llm_kwargs["api_key"] = api_key for key in ("timeout", "max_retries", "reasoning_effort", "api_key", "callbacks"): if key in self.kwargs: