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

89 lines
4.1 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:8091" # 终态端口(浸泡期由 .env 覆盖 7921)
qa_api_path: str = "/api/v1/qa-v1-1-73"
rag_base_url: str = "http://127.0.0.1:8092" # 终态端口(浸泡期由 .env 覆盖 8001)
rag_alt_base_url: str = "http://127.0.0.1:8093" # 终态端口(浸泡期由 .env 覆盖 7911)
rag_legacy_base_url: str = "http://127.0.0.1:8093"
# ---- 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
# ---- 文档生成(docgen,P2;对 vstore 的全部访问经 services/docgen/client.py 透传)----
docgen_root: str = "data/docgen" # 制品落盘根目录(相对 BFF cwd)
docgen_artifact_ttl_days: int = 30 # 制品保留天数(越界由 /library 清理时剔除)
docgen_quota_gb: float = 50.0 # 制品目录配额(GB,超限返回 QUOTA_EXCEEDED 信封)
docgen_llm_base_url: str = "https://api.deepseek.com" # 文档生成 LLM(deepseek,仅服务层消费,绝不下发浏览器)
docgen_llm_api_key: str = "" # LLM 凭据(只存在于本进程;默认空=未配置,生成 503)
docgen_llm_model: str = "deepseek-chat"
docgen_llm_timeout: float = 300.0 # LLM 单次调用读超时(秒)
# ---- vstore(8094,文档资料向量库;BFF 不透传其错误形态,见 routers/docgen.py)----
vstore_base_url: str = "http://127.0.0.1:8094"
# ---- 多轮记忆(S2)----
bff_enable_humanize: bool = True # Humanizer 总开关(会话开关在其下)
bff_history_rounds: int = 3 # 携带最近 N 轮问答
bff_history_max_question_chars: int = 4000 # 单条 user 文本截断
bff_history_max_answer_chars: int = 12000 # 单条 assistant 答案截断
# ---- 生信服务反代(FR-BIO-027/028;BIOFLOW_ENABLED 为假时反代路由不注册)----
bioflow_enabled: bool = False # 三形态部署开关(默认关:只部署 rag 无生信痕迹)
bioflow_service_url: str = "http://127.0.0.1:8098" # 生信服务 8098(BFF 流式反代目标)
# ---- 生产形态: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()