mirror of
https://github.com/The-Swarm-Corporation/AutoHedge.git
synced 2026-10-02 05:24:49 +08:00
fix env stuff on cli
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
from autohedge.env_loader import load_env
|
||||
|
||||
load_env()
|
||||
|
||||
from autohedge.main import AutoHedge
|
||||
|
||||
__all__ = ["AutoHedge"]
|
||||
|
||||
+7
-2
@@ -10,9 +10,14 @@ from rich.panel import Panel
|
||||
from rich.text import Text
|
||||
from rich.columns import Columns
|
||||
from rich import box
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
from autohedge.env_loader import load_env, require_openai_key
|
||||
|
||||
load_env()
|
||||
if not require_openai_key():
|
||||
Console().print(
|
||||
"[yellow]Warning: OPENAI_API_KEY not set. Set it in .env or export it.[/]"
|
||||
)
|
||||
|
||||
try:
|
||||
from importlib.metadata import version as _version
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
"""
|
||||
Load .env from project root so API keys work when running from any directory.
|
||||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
|
||||
def find_project_env() -> Path | None:
|
||||
"""Find .env by walking up from cwd (so CLI/scripts work from any subdir)."""
|
||||
cwd = Path(os.getcwd()).resolve()
|
||||
for parent in [cwd, *cwd.parents]:
|
||||
env_file = parent / ".env"
|
||||
if env_file.is_file():
|
||||
return env_file
|
||||
return None
|
||||
|
||||
|
||||
def load_env() -> None:
|
||||
"""Load .env from project root; fall back to cwd. Does not override existing env."""
|
||||
env_path = find_project_env()
|
||||
if env_path:
|
||||
load_dotenv(env_path, override=False)
|
||||
else:
|
||||
load_dotenv()
|
||||
|
||||
|
||||
def require_openai_key() -> bool:
|
||||
"""Return True if OPENAI_API_KEY is set (required for swarms gpt-4.x)."""
|
||||
return bool(os.getenv("OPENAI_API_KEY"))
|
||||
@@ -6,7 +6,6 @@ from swarms import Conversation
|
||||
from autohedge.workers import director_agent
|
||||
|
||||
|
||||
|
||||
class AutoHedge:
|
||||
"""
|
||||
Main trading system that coordinates all agents and manages the trading cycle.
|
||||
|
||||
+1
-4
@@ -1,7 +1,4 @@
|
||||
from dotenv import load_dotenv
|
||||
from autohedge.main import AutoHedge
|
||||
|
||||
load_dotenv()
|
||||
from autohedge import AutoHedge # loads .env from project root
|
||||
|
||||
# Initialize the trading system (tickers are derived from the task by the director)
|
||||
trading_system = AutoHedge(
|
||||
|
||||
+2
-1
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.poetry]
|
||||
name = "autohedge"
|
||||
version = "0.1.3"
|
||||
version = "0.1.5"
|
||||
description = "autohedge - TGSC"
|
||||
license = "MIT"
|
||||
authors = ["Kye Gomez <kye@apac.ai>"]
|
||||
@@ -34,6 +34,7 @@ swarm-models = "*"
|
||||
httpx = "*"
|
||||
solders = "*"
|
||||
yfinance = "*"
|
||||
python-dotenv = "*"
|
||||
|
||||
|
||||
[tool.poetry.group.lint.dependencies]
|
||||
|
||||
Reference in New Issue
Block a user