| import os |
| import tempfile |
| from pathlib import Path |
|
|
|
|
| DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space" |
| HF_ROUTER_URL = "https://router.huggingface.co/v1/chat/completions" |
| HF_TEXT_MODEL = os.getenv("HF_TEXT_MODEL", "openai/gpt-oss-20b:cheapest") |
| HF_VISION_MODEL = os.getenv("HF_VISION_MODEL", "") |
| HF_PLANNER_USE_RESPONSE_FORMAT = ( |
| os.getenv("HF_PLANNER_USE_RESPONSE_FORMAT", "0").strip().lower() |
| in {"1", "true", "yes", "on"} |
| ) |
| MAX_EVIDENCE_CHARS = int(os.getenv("MAX_EVIDENCE_CHARS", "18000")) |
| MAX_AGENT_STEPS = int(os.getenv("MAX_AGENT_STEPS", "4")) |
| MAX_TOOL_OUTPUT_CHARS = int(os.getenv("MAX_TOOL_OUTPUT_CHARS", "8000")) |
| CACHE_DIR = Path(os.getenv("GAIA_CACHE_DIR", tempfile.gettempdir())) / "gaia_agent_files" |
| REQUEST_HEADERS = { |
| "User-Agent": ( |
| "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) " |
| "AppleWebKit/537.36 (KHTML, like Gecko) " |
| "Chrome/125.0.0.0 Safari/537.36" |
| ) |
| } |
|
|
|
|
| def get_hf_token() -> str | None: |
| """读取 Hugging Face Token。Space Secrets 中建议使用 HF_TOKEN。""" |
| token = ( |
| os.getenv("HF_TOKEN") |
| or os.getenv("HUGGING_FACE_HUB_TOKEN") |
| or os.getenv("HUGGINGFACEHUB_API_TOKEN") |
| ) |
| if token: |
| return token |
|
|
| local_token_path = Path.home() / ".cache" / "huggingface" / "token" |
| if local_token_path.exists(): |
| return local_token_path.read_text(encoding="utf-8").strip() |
| return None |
|
|