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

111 lines
5.5 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 流式反代目标)
# ---- 论文撰写服务(paper_writer_service 8097;PAPER_WRITER_ENABLED 为假时路由不注册)----
paper_writer_enabled: bool = False
paper_writer_url: str = "http://127.0.0.1:8097"
paper_writer_read_timeout: float = 360.0 # write_paper_section 同步长调用读超时(秒)
# ---- 科研审稿服务(review_service 8100;REVIEW_ENABLED 为假时路由不注册)----
review_enabled: bool = False
review_service_url: str = "http://127.0.0.1:8100"
review_read_timeout: float = 360.0 # presubmit 上传+LLM 长调用读超时(秒)
# ---- 管理后台(admin console + 行为日志)----
admin_seed_username: str = "admin" # 种子管理员用户名(启动时若无 admin 则创建)
admin_seed_password: str = "admin" # 种子管理员初始密码
admin_token_ttl_seconds: int = 86400 # 管理员会话凭据有效期(秒)
admin_dist_dir: str = "admin/dist" # 管理后台前端构建产物(BFF 托管 /admin)
log_dir: str = "data/logs" # 行为日志目录(每日一个 JSONL 文件)
log_retention_days: int = 0 # 日志保留天数(0=不清理)
# ---- 用户端鉴权(普通用户登录;AUTH_ENABLED 为假=匿名放行,兼容浸泡期)----
auth_enabled: bool = False
user_token_ttl_seconds: int = 86400 # 普通用户会话凭据有效期(秒)
# ---- 生产形态: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()