File size: 1,423 Bytes
6c511d6
 
 
 
 
 
 
 
 
d6b82a1
 
 
 
6c511d6
e7e1e90
 
6c511d6
 
 
 
 
 
 
 
 
 
 
 
e7e1e90
6c511d6
 
 
 
e7e1e90
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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