Add embedded Hugging Face token fallback

This commit is contained in:
CoolBoy
2026-07-10 01:02:25 +08:00
parent 597d3b1d86
commit 5460fbd108
4 changed files with 10 additions and 6 deletions

View File

@@ -15,12 +15,13 @@ submission poller in a child process.
## Runtime Environment ## Runtime Environment
The image includes a single-account submission token fallback for the agent The image includes single-account ModelHub and Hugging Face token fallbacks for
platform. Environment variables can override it without rebuilding the image. the agent platform. Environment variables can override them without rebuilding
the image.
- `MODELHUB_XC_TOKEN`, `XC_TOKEN`, or `MODELHUB_TOKEN` for ModelHub API authentication - `MODELHUB_XC_TOKEN`, `XC_TOKEN`, or `MODELHUB_TOKEN` for ModelHub API authentication
- `MODELHUB_JWT_TOKEN` or `JWT_TOKEN` can be used instead when the platform provides a JWT - `MODELHUB_JWT_TOKEN` or `JWT_TOKEN` can be used instead when the platform provides a JWT
- `HF_TOKEN` optional, but recommended for Hugging Face API limits - `HF_TOKEN` optional override for the embedded Hugging Face fallback token
- `STRATEGY_ID` is expected to be injected by the ModelHub agent platform and is attached to submissions for strategy attribution; it is not an API authentication token - `STRATEGY_ID` is expected to be injected by the ModelHub agent platform and is attached to submissions for strategy attribution; it is not an API authentication token
Optional tuning: Optional tuning:

View File

@@ -9,7 +9,7 @@ import time
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path from pathlib import Path
from modelhub_submmit_api.defaults import EMBEDDED_MODELHUB_XC_TOKEN from modelhub_submmit_api.defaults import EMBEDDED_HF_TOKEN, EMBEDDED_MODELHUB_XC_TOKEN
HOST = "0.0.0.0" HOST = "0.0.0.0"
@@ -75,7 +75,7 @@ def _worker_command() -> list[str]:
def _config() -> dict[str, object]: def _config() -> dict[str, object]:
return { return {
"strategy_id_present": bool(os.getenv("STRATEGY_ID")), "strategy_id_present": bool(os.getenv("STRATEGY_ID")),
"hf_token_present": bool(os.getenv("HF_TOKEN")), "hf_token_present": bool(os.getenv("HF_TOKEN") or EMBEDDED_HF_TOKEN),
"modelhub_auth_present": _has_modelhub_auth(), "modelhub_auth_present": _has_modelhub_auth(),
"config_error": config_error, "config_error": config_error,
"worker_running": worker is not None and worker.poll() is None, "worker_running": worker is not None and worker.poll() is None,

View File

@@ -1 +1,2 @@
EMBEDDED_MODELHUB_XC_TOKEN = "a14776f6e7ad4c04a1710260613c294c" EMBEDDED_MODELHUB_XC_TOKEN = "a14776f6e7ad4c04a1710260613c294c"
EMBEDDED_HF_TOKEN = "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"

View File

@@ -4,7 +4,7 @@ import argparse
import os import os
from pathlib import Path from pathlib import Path
from defaults import EMBEDDED_MODELHUB_XC_TOKEN from defaults import EMBEDDED_HF_TOKEN, EMBEDDED_MODELHUB_XC_TOKEN
DEFAULT_KEY_PATH = Path("KEY.md") DEFAULT_KEY_PATH = Path("KEY.md")
@@ -43,6 +43,8 @@ def ensure_tokens(args: argparse.Namespace) -> None:
if not getattr(args, "hf_token", None): if not getattr(args, "hf_token", None):
args.hf_token = os.getenv("HF_TOKEN") or values.get("HF_TOKEN") args.hf_token = os.getenv("HF_TOKEN") or values.get("HF_TOKEN")
if not getattr(args, "hf_token", None):
args.hf_token = EMBEDDED_HF_TOKEN
modelhub_token = getattr(args, "modelhub_token", None) modelhub_token = getattr(args, "modelhub_token", None)
if not modelhub_token: if not modelhub_token: