Files
mnote/wolai-backend/app/config.py
T

39 lines
1.3 KiB
Python
Raw Normal View History

2025-11-23 10:55:04 +08:00
from functools import lru_cache
2026-02-01 08:47:40 +08:00
from pathlib import Path
2025-11-23 10:55:04 +08:00
from pydantic_settings import BaseSettings, SettingsConfigDict
2026-02-01 08:47:40 +08:00
ENV_ALL_PATH = Path(__file__).resolve().parents[2] / ".env.all"
2025-11-23 10:55:04 +08:00
2026-02-01 08:47:40 +08:00
class Settings(BaseSettings):
"""集中管理项目配置,来源于 .env.all / 环境变量。"""
# 约定:全局仅使用仓库根目录的 .env.all 作为配置来源(生产优先)。
# 说明:这里使用绝对路径,避免因 cwd 不同导致读取失败。
model_config = SettingsConfigDict(
env_file=str(ENV_ALL_PATH), env_file_encoding="utf-8", extra="ignore"
)
2025-11-23 10:55:04 +08:00
2026-01-17 10:12:53 +08:00
# 说明:项目迁移到 Convex 的过程中,后端可能暂时不依赖 Supabase。
# 因此这里给出空字符串默认值,避免本地未配置 .env 时无法启动开发服务器。
supabase_url: str = ""
supabase_service_role_key: str = ""
2025-11-23 10:55:04 +08:00
redis_url: str = "redis://localhost:6379/0"
frontend_url: str = "http://localhost:3000"
openai_api_key: str = ""
mnote_ai_default_model: str = ""
mnote_ai_orchestrator_api_key: str = ""
openai_agents_session_db_path: str = ""
2026-01-17 10:12:53 +08:00
lightrag_db_url: str = ""
2025-11-23 10:55:04 +08:00
lightrag_collection: str = "wolai-docs"
2026-04-13 19:21:42 +08:00
@lru_cache
def get_settings() -> Settings:
"""惰性实例化设置,避免重复读取文件。"""
return Settings()
settings = get_settings()