Files
PlantAI-rag-new/backend/app/config.py
T

66 lines
2.3 KiB
Python
Raw Normal View History

"""config.py —— 环境变量驱动的 BFF 配置(pydantic-settings)。
全部键见 backend/.env.example。凭据类键(Neo4j)只存在于本进程,
**绝不下发到浏览器**(不进入任何 API 响应)。
上游拓扑与默认值依据 docs/DISCOVERY.md:
- QA 7920:`/api/v1/qa-v1-1-73`(DISCOVERY §4)
- RAG 8000(Methodology API,DISCOVERY §3)/ ragAlt 7900(protected 容器,§3.7)
- Neo4j 候选顺序:18788(direct,首选)→ 19788(normalized)→ 17687(protected,空库)
凭据见 DISCOVERY §2.1,可由 BFF_NEO4J_* 环境变量覆盖(测试/部署)。
"""
from __future__ import annotations
from functools import lru_cache
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
extra="ignore",
)
# ---- 应用 ----
app_name: str = "plantai-rag-new-bff"
version: str = "0.1.0"
# ---- 上游地址(只读消费,见 ARCHITECTURE.md §2)----
qa_base_url: str = "http://127.0.0.1:7920"
qa_api_path: str = "/api/v1/qa-v1-1-73"
rag_base_url: str = "http://127.0.0.1:8000"
rag_alt_base_url: str = "http://127.0.0.1:7900"
# ---- Neo4j 候选(顺序即回退顺序,首选 18788;凭据见 DISCOVERY §2.1)----
neo4j_bolt_uris: str = (
"bolt://127.0.0.1:18788,bolt://127.0.0.1:19788,bolt://127.0.0.1:17687"
)
neo4j_user: str = "neo4j"
neo4j_passwords: str = (
"" # 真实凭据在 backend/.env(不入 git),见 backend/.env.example
)
# ---- 超时阶梯(秒)----
timeout_health: float = 1.0 # 健康探测
timeout_qa_chat: float = 300.0 # qa chat(读超时)
timeout_qa_search: float = 180.0 # qa search(读超时)
timeout_upload: float = 600.0 # 抽取 upload(读超时)
timeout_extraction: float = 15.0 # 抽取其余接口
# ---- 本地 ----
db_path: str = "backend/data/plantai.db"
health_cache_ttl: float = 5.0
# ---- 生产形态:BFF 静态托管 frontend/dist(ARCHITECTURE.md §3,M6 挂载)----
frontend_dist_dir: str = "frontend/dist"
@lru_cache(maxsize=1)
def get_settings() -> Settings:
return Settings()
settings = get_settings()