diff --git a/python/valuecell/agents/sec_agent.py b/python/valuecell/agents/sec_agent.py index 485d1088f..bbc21e122 100644 --- a/python/valuecell/agents/sec_agent.py +++ b/python/valuecell/agents/sec_agent.py @@ -344,7 +344,9 @@ async def _process_financial_data_query( Please ensure the analysis is objective and professional, based on actual data, avoiding excessive speculation. """ - response_stream: Iterator[RunResponseEvent] = self.analysis_agent.run( + response_stream: Iterator[ + RunResponseEvent + ] = await self.analysis_agent.arun( analysis_prompt, stream=True, stream_intermediate_steps=True ) for event in response_stream: @@ -440,7 +442,9 @@ async def _process_fund_holdings_query( Please ensure the analysis is objective and professional, based on actual data, avoiding excessive speculation. """ - response_stream: Iterator[RunResponseEvent] = self.analysis_agent.run( + response_stream: Iterator[ + RunResponseEvent + ] = await self.analysis_agent.arun( analysis_prompt, stream=True, stream_intermediate_steps=True ) for event in response_stream: diff --git a/python/valuecell/server/config/settings.py b/python/valuecell/server/config/settings.py index 329bd92ca..092db7d9c 100644 --- a/python/valuecell/server/config/settings.py +++ b/python/valuecell/server/config/settings.py @@ -5,6 +5,23 @@ from functools import lru_cache +def _get_project_root() -> str: + """Get project root directory path. + + Layout assumption: this file is at repo_root/python/valuecell/server/config/settings.py + We walk up 4 levels to reach repo_root. + """ + here = os.path.dirname(__file__) + repo_root = os.path.abspath(os.path.join(here, "..", "..", "..", "..")) + return repo_root + + +def _default_db_path() -> str: + """Get default database path in project root.""" + repo_root = _get_project_root() + return f"sqlite:///{os.path.join(repo_root, 'valuecell.db')}" + + class Settings: """Server configuration settings.""" @@ -16,7 +33,7 @@ def __init__(self): self.APP_ENVIRONMENT = os.getenv("APP_ENVIRONMENT", "development") # API Configuration - self.API_HOST = os.getenv("API_HOST", "localhost") + self.API_HOST = os.getenv("API_HOST", "0.0.0.0") self.API_PORT = int(os.getenv("API_PORT", "8000")) self.API_DEBUG = os.getenv("API_DEBUG", "false").lower() == "true" @@ -25,23 +42,7 @@ def __init__(self): self.CORS_ORIGINS = cors_origins.split(",") if cors_origins != "*" else ["*"] # Database Configuration - self.DATABASE_URL = os.getenv( - "DATABASE_URL", "sqlite:///valuecell/server/db/valuecell.db" - ) - self.DB_ECHO = os.getenv("DB_ECHO", "false").lower() == "true" - - # Redis Configuration - self.REDIS_URL = os.getenv("REDIS_URL", "redis://localhost:6379") - - # Security Configuration - self.SECRET_KEY = os.getenv("SECRET_KEY", "your-secret-key-here") - self.ACCESS_TOKEN_EXPIRE_MINUTES = int( - os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", "30") - ) - - # Logging Configuration - self.LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO") - self.LOG_FORMAT = os.getenv("LOG_FORMAT", "json") + self.DATABASE_URL = os.getenv("VALUECELL_SQLITE_DB", _default_db_path()) # File Paths self.BASE_DIR = Path(__file__).parent.parent.parent @@ -51,37 +52,9 @@ def __init__(self): # I18n Configuration self.LOCALE_DIR = self.BASE_DIR / "configs/locales" - # Agent Configuration - self.AGENT_TIMEOUT = int(os.getenv("AGENT_TIMEOUT", "300")) # 5 minutes - self.MAX_CONCURRENT_AGENTS = int(os.getenv("MAX_CONCURRENT_AGENTS", "10")) - - # External APIs - self.OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") - self.FINNHUB_API_KEY = os.getenv("FINNHUB_API_KEY") - self.ALPHA_VANTAGE_API_KEY = os.getenv("ALPHA_VANTAGE_API_KEY") - - @property - def is_development(self) -> bool: - """Check if running in development mode.""" - return self.APP_ENVIRONMENT == "development" - - @property - def is_production(self) -> bool: - """Check if running in production mode.""" - return self.APP_ENVIRONMENT == "production" - def get_database_config(self) -> dict: """Get database configuration.""" - return { - "url": self.DATABASE_URL, - "echo": self.DB_ECHO, - } - - def get_redis_config(self) -> dict: - """Get Redis configuration.""" - return { - "url": self.REDIS_URL, - } + return {"url": self.DATABASE_URL} def update_language(self, language: str) -> None: """Update current language setting. diff --git a/python/valuecell/server/db/connection.py b/python/valuecell/server/db/connection.py index 05d5000cb..e5cb37633 100644 --- a/python/valuecell/server/db/connection.py +++ b/python/valuecell/server/db/connection.py @@ -34,7 +34,6 @@ def _initialize_engine(self) -> None: self.engine = create_engine( database_config["url"], - echo=database_config["echo"], connect_args=connect_args, poolclass=StaticPool if database_config["url"].startswith("sqlite")