#!/usr/bin/env python3 """HF API client configuration for arca-processor""" import os from dataclasses import dataclass from typing import Dict, Optional from huggingface_hub import HfApi @dataclass(frozen=True) class HFConfig: token: Optional[str] dataset_repo: str def _is_dev_mode() -> bool: value = str(os.environ.get("NODE_ENV") or os.environ.get("ENV") or "").strip().lower() return value in {"dev", "development", "local"} def get_hf_config() -> HFConfig: token = str(os.environ.get("HF_TOKEN") or "").strip() dataset_repo = str(os.environ.get("DATASET_REPO") or "ArcaThread/arca-thread-priors").strip() if not token and not _is_dev_mode(): raise RuntimeError("HF_TOKEN is required in non-dev environments") return HFConfig(token=token or None, dataset_repo=dataset_repo) def get_hf_api() -> HfApi: cfg = get_hf_config() return HfApi(token=cfg.token) def get_hf_headers() -> Dict[str, str]: cfg = get_hf_config() if not cfg.token: return {} return {"Authorization": f"Bearer {cfg.token}"}