Files
ecom-dmb/apps/agent/config/settings.py
T

57 lines
2.0 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.
"""应用配置(环境变量)。"""
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 = "ecom-dmb-agent"
host: str = "0.0.0.0"
port: int = 8200
cors_origins: str = "http://localhost:5173,http://localhost:5666"
# 与 Java server jwt.secret 一致(HS512)
jwt_secret: str = "your-secret-key-here-must-be-at-least-64-bytes-long-for-hs512-algorithm-security"
jwt_algorithms: str = "HS512"
mongo_uri: str = "mongodb://ecom_dmb_agent_dev:ecom_dmb_agent_dev@192.168.3.100:27017/?authSource=ecom_dmb_agent_dev"
mongo_db: str = "ecom_dmb_agent_dev"
# 须与 Server Redis 同库,才能命中 agent:llm:rt:{companyId}
redis_url: str = "redis://:redis_qinghua@192.168.3.100:6379/2"
llm_cache_ttl_seconds: int = 600
# Java Server 根地址(内部拉 LLM 运行时)
server_base_url: str = "http://localhost:8080"
# 仅本地开发:公司未配置时的 fallback(生产勿用)
llm_fallback_enabled: bool = True
llm_fallback_base_url: str = "https://api.openai.com/v1"
llm_fallback_api_key: str = ""
llm_fallback_model: str = "gpt-4o-mini"
mcp_base_url: str = "http://localhost:8080/mcp"
mcp_bearer_token: str = "dev-agent-mcp-token"
mcp_tools_enabled: bool = True
chat_history_limit: int = 40
# 从 Mongo 最多拉多少条再按 token 裁剪(应 ≥ 条数窗口时代的 limit)
chat_history_fetch_limit: int = 200
# 未配置 context_window 且模型名无法识别时的默认
llm_default_context_window: int = 128000
# 为模型输出与本轮 tool 预留的 token
context_reserve_output_tokens: int = 4096
context_reserve_tool_tokens: int = 8192
@property
def cors_origin_list(self) -> list[str]:
return [o.strip() for o in self.cors_origins.split(",") if o.strip()]
@lru_cache
def get_settings() -> Settings:
return Settings()