#!/usr/bin/env python3 """Generate crates/buzz-agent/src/databricks_model_names.rs from models.dev. Usage: python3 scripts/generate-databricks-model-names.py \ > crates/buzz-agent/src/databricks_model_names.rs Fetches https://models.dev/api.json, extracts providers.databricks.models (the authoritative curated name registry used by goose and others), and emits a static Rust slice of (id, display_name) pairs sorted by ID. Re-run whenever Databricks ships a new managed endpoint and commit the diff. """ import json import subprocess import sys URL = "https://models.dev/api.json" def fetch(url: str) -> bytes: # urllib blocks with HTTP 403 without a browser User-Agent; use curl when # available so the script works in hermit environments where curl is pinned. result = subprocess.run( ["curl", "-s", "-A", "Mozilla/5.0", url], capture_output=True, check=True, ) return result.stdout def rust_str(s: str) -> str: """Emit a Rust string literal with double quotes.""" escaped = s.replace("\\", "\\\\").replace('"', '\\"') return f'"{escaped}"' def main() -> None: raw = fetch(URL) data = json.loads(raw) models: dict = data["databricks"]["models"] entries = sorted( (k, v["name"] if isinstance(v, dict) else k) for k, v in models.items() ) lines = [ "// GENERATED by scripts/generate-databricks-model-names.py", "// Source: https://models.dev/api.json -- providers.databricks.models", "// Refresh: python3 scripts/generate-databricks-model-names.py \\", "// > crates/buzz-agent/src/databricks_model_names.rs", "//", "// Do not hand-edit -- rerun the script to update.", "", "/// Curated display names for known Databricks AI Gateway endpoints.", "///", "/// Keys are endpoint IDs returned verbatim by the discovery APIs.", "/// Values are human-readable display names sourced from models.dev.", "///", "/// Unknown endpoint IDs are displayed as their raw ID -- no guessing.", "pub(crate) static DATABRICKS_MODEL_NAMES: &[(&str, &str)] = &[", ] for id_, name in entries: lines.append(f" ({rust_str(id_)}, {rust_str(name)}),") lines += ["];", ""] sys.stdout.write("\n".join(lines)) if __name__ == "__main__": main()