Files
PlantAI-rag-new/sdk/app/config.py
T
jerryandClaude Fable 5 0875bb036c P0/M1: 四部分重构——frontend→ui、backend→sdk 改名 + 引用修复 + 骨架
- git mv 保留历史:ui/(Vue3+Vite)、sdk/(BFF 中间层)
- 路径语义修正:db_path/figures_cache 改相对 sdk/(BFF cwd),
  历史库 sdk/backend/data 迁移至 sdk/data/(会话/图片缓存无损)
- 引用修复 ~15 处:config.py、deploy/*.sh、vitest/playwright 配置、
  单测导入路径、docs、README、gitignore、.env.example
- 骨架:agent/{qa,methodology,legacy-rag,vendor}、knowledge/manifest.yaml、
  tooling/{compile,kb,crypto,assemble,audit,tools,scripts} + README
- 门禁验证:sdk pytest 125 通过、ui vitest 158 通过、
  生产 BFF 脚本重启四上游全绿 + 静态托管 + 会话库无损

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-31 12:56:47 +08:00

66 lines
2.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""config.py —— 环境变量驱动的 BFF 配置(pydantic-settings)。
全部键见 sdk/.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 = (
"" # 真实凭据在 sdk/.env(不入 git),见 sdk/.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 = "data/plantai.db" # 相对 sdk/(BFF cwd),bff_restart.sh 保证
health_cache_ttl: float = 5.0
# ---- 生产形态:BFF 静态托管 ui/dist(ARCHITECTURE.md §3,M6 挂载)----
frontend_dist_dir: str = "ui/dist" # 生产形态:静态托管 ui/dist
@lru_cache(maxsize=1)
def get_settings() -> Settings:
return Settings()
settings = get_settings()