Datasets:
Download scripts/check_keys.py from Nabidnur/RoboRACE-Bench: direct link, hf CLI and curl.
- Browser
- Download file 2.11 kB
-
https://huggingface.co/datasets/Nabidnur/RoboRACE-Bench/resolve/main/scripts/check_keys.py
- Command line
-
hf download hf://datasets/Nabidnur/RoboRACE-Bench/scripts/check_keys.py
-
curl -L -o check_keys.py https://huggingface.co/datasets/Nabidnur/RoboRACE-Bench/resolve/main/scripts/check_keys.py
2.11 kB
| #!/usr/bin/env python3 | |
| """Check which API keys are configured and working. Never prints key values. | |
| python scripts/check_keys.py # ping each configured LLM provider + HF | |
| python scripts/check_keys.py --list-models # also list live model ids per provider | |
| """ | |
| import argparse | |
| import json | |
| import os | |
| import sys | |
| import urllib.request | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) | |
| from robotics.llm.providers import PROVIDERS, LLMError, chat, list_models # noqa: E402 | |
| def check_hf() -> str: | |
| tok = os.environ.get("HF_TOKEN") | |
| if not tok: | |
| return "not set" | |
| req = urllib.request.Request("https://huggingface.co/api/whoami-v2", | |
| headers={"Authorization": f"Bearer {tok}"}) | |
| try: | |
| with urllib.request.urlopen(req, timeout=20) as r: | |
| return f"ok (user: {json.loads(r.read()).get('name')})" | |
| except Exception as e: # noqa: BLE001 | |
| return f"FAILED ({type(e).__name__})" | |
| def main() -> None: | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--list-models", action="store_true") | |
| a = ap.parse_args() | |
| print(f"{'HF_TOKEN':20} {check_hf()}") | |
| for name in ("KAGGLE_API_TOKEN", "TINKER_API_KEY", "REACTOR_API_KEY", "WANDB_API_KEY"): | |
| print(f"{name:20} {'set' if os.environ.get(name) else 'not set'}") | |
| for p in PROVIDERS.values(): | |
| if not p.api_key: | |
| print(f"{p.key_env:20} not set") | |
| continue | |
| try: | |
| text, _ = chat([{"role": "user", "content": "Reply with the word OK."}], | |
| providers=[p.name], max_tokens=256, retries_per_provider=1) | |
| status = f"ok ({p.model}: {text.strip()[:20]!r})" | |
| except LLMError as e: | |
| status = f"FAILED {e}" | |
| print(f"{p.key_env:20} {status}") | |
| if a.list_models: | |
| try: | |
| print(" models:", ", ".join(list_models(p)[:40])) | |
| except Exception as e: # noqa: BLE001 | |
| print(f" models: unavailable ({type(e).__name__})") | |
| if __name__ == "__main__": | |
| main() | |