Download app/config.py from simonu5/TriChat: direct link, hf CLI and curl.
- Browser
- Download file 4.19 kB
-
https://huggingface.co/spaces/simonu5/TriChat/resolve/main/app/config.py
- Command line
-
hf download hf://spaces/simonu5/TriChat/app/config.py
-
curl -L -o config.py https://huggingface.co/spaces/simonu5/TriChat/resolve/main/app/config.py
4.19 kB
| """所有設定都從環境變數讀取(在 Hugging Face Space 的 Settings → Secrets 裡設定)。""" | |
| import os | |
| def _bool(v: str | None, default: bool) -> bool: | |
| if v is None or v == "": | |
| return default | |
| return v.strip().lower() in ("1", "true", "yes", "on") | |
| # 必填 | |
| APP_SECRET = os.getenv("APP_SECRET", "") # 前端登入密碼 | |
| TURSO_DATABASE_URL = os.getenv("TURSO_DATABASE_URL", "") # libsql://xxx.turso.io | |
| TURSO_AUTH_TOKEN = os.getenv("TURSO_AUTH_TOKEN", "") | |
| # 模型不用環境變數:全部在前端「🤖 模型」面板裡新增(存在 Turso) | |
| # 選填 | |
| TAVILY_API_KEY = os.getenv("TAVILY_API_KEY", "") # 有就用 Tavily 搜尋,沒有就用 ddgs | |
| MAX_AGENT_STEPS = int(os.getenv("MAX_AGENT_STEPS", "200")) # 單次執行最多幾輪工具調用的預設值(「設定」面板可改),到了可按「繼續執行」 | |
| ENABLE_PYTHON_TOOL = _bool(os.getenv("ENABLE_PYTHON_TOOL"), True) | |
| SESSION_DAYS = int(os.getenv("SESSION_DAYS", "30")) # 登入有效天數 | |
| HISTORY_LIMIT = int(os.getenv("HISTORY_LIMIT", "60")) # 帶入上下文的歷史訊息數 | |
| DEFAULT_TZ = os.getenv("DEFAULT_TZ", "Asia/Hong_Kong") | |
| ENABLE_SHELL_TOOL = _bool(os.getenv("ENABLE_SHELL_TOOL"), True) | |
| WORKDIR = os.getenv("WORKDIR", "/tmp/workspace") # run_python / run_shell 的工作目錄 | |
| SKILLS_DIR = os.getenv("SKILLS_DIR", "/tmp/skills") # 技能檔案落地目錄 | |
| GITHUB_TOKEN = os.getenv("GITHUB_TOKEN", "") # 選填:安裝私有 repo 的技能 | |
| # 首次啟動自動安裝的技能(逗號分隔的 GitHub 資料夾網址;設成空字串可停用)。 | |
| # 已裝過或你手動刪掉的不會重裝。預設是一組開發向技能。 | |
| _DEV_SKILLS = ",".join( | |
| [f"https://github.com/obra/superpowers/tree/main/skills/{n}" for n in ( | |
| "brainstorming", "writing-plans", "executing-plans", "test-driven-development", | |
| "systematic-debugging", "requesting-code-review", "receiving-code-review", | |
| "verification-before-completion")] | |
| + [f"https://github.com/anthropics/skills/tree/main/skills/{n}" for n in ( | |
| "mcp-builder", "frontend-design", "skill-creator")]) | |
| DEFAULT_SKILLS = [u.strip() for u in os.getenv("DEFAULT_SKILLS", _DEV_SKILLS).split(",") if u.strip()] | |
| LLM_TIMEOUT = int(os.getenv("LLM_TIMEOUT", "900")) # 等模型回應(兩段輸出之間)最多幾秒;慢模型/長思考可再調高 | |
| LLM_CONNECT_TIMEOUT = int(os.getenv("LLM_CONNECT_TIMEOUT", "60")) | |
| PROJECT_MAX_FILE_MB = int(os.getenv("PROJECT_MAX_FILE_MB", "10")) # 單檔超過就不存進資料庫 | |
| PROJECT_MAX_TOTAL_MB = int(os.getenv("PROJECT_MAX_TOTAL_MB", "500")) # 每個專案存進資料庫的上限 | |
| TOOL_MEM_GB = int(os.getenv("TOOL_MEM_GB", "12")) # run_python / run_shell 單次最多用多少記憶體(0=不限) | |
| MAX_TOOL_TIMEOUT = int(os.getenv("MAX_TOOL_TIMEOUT", "3600")) # run_python / run_shell 單次最長秒數 | |
| MCP_CONNECT_TIMEOUT = int(os.getenv("MCP_CONNECT_TIMEOUT", "60")) | |
| MCP_CALL_TIMEOUT = int(os.getenv("MCP_CALL_TIMEOUT", "120")) | |
| DEFAULT_SYSTEM_PROMPT = os.getenv( | |
| "SYSTEM_PROMPT", | |
| """你是使用者的私人 AI 助理(AI agent),可以調用工具完成任務。 | |
| 原則: | |
| - 需要最新資訊、事實核查時,先用 web_search,再用 fetch_url 讀原文,回答時附上來源網址。 | |
| - 需要計算、處理資料、畫圖或驗證程式時,用 run_python 實際執行,不要心算。 | |
| - 寫程式時:用 list_files / read_file 先看清楚現有程式,用 write_file / edit_file 改檔案,用 run_shell 跑測試、裝依賴、執行;改完要實際跑過驗證。 | |
| - 檔案都在目前專案資料夾(也是 run_python / run_shell 的工作目錄),會自動永久保存。 | |
| - 使用者告訴你值得長期記住的事(偏好、身份、長期計劃)時,用 save_memory 存下來;需要回想時用 search_memory。 | |
| - 任務符合某個技能(Skill)的描述時,先用 load_skill 讀完整說明,再照著做。 | |
| - MCP 工具(名稱以 mcp_ 開頭)是外部服務,按其描述使用。 | |
| - 回答用使用者的語言,簡潔、直接,善用 Markdown。 | |
| """, | |
| ) | |