SPB Git forge

spb/ai-atlas

Public
41commits 1branches 0releases
4.6 MBsize
maindefault branch
12 days agolast push
HTML 77.2% TypeScript 10.5% Python 9.6% JavaScript 2.5%
2.8 KB · 96 lines python
Raw Blame History
1"""Stable internal identifiers: prefixed ULIDs (`model_01J…`). URLs and names change; ids never do."""2from __future__ import annotations34import re56from slugify import slugify as _slugify7from ulid import ULID89PREFIXES: dict[str, str] = {10    "model": "model",11    "model_family": "family",       # Llama 4, Qwen3.6, Claude — groups model releases12    "artifact": "artifact",         # checkpoint / quantisation / conversion of a model (never a model of its own)13    "company": "company",14    "organization": "org",15    "researcher": "person",16    "paper": "paper",17    "dataset": "dataset",18    "benchmark": "bench",19    "provider": "provider",20    "framework": "framework",21    "library": "lib",22    "repository": "repo",23    "tool": "tool",24    "agent": "agent",25    "application": "app",26    "hardware": "hw",27    "runtime": "runtime",28    "quantization": "quant",29    "license": "license",30    "conference": "conf",31    "university": "univ",32    "lab": "lab",33    "product": "product",34    "release": "release",35    "regulation": "reg",36    "incident": "incident",37    "country": "country",38    "mcp_server": "mcp",39    "robot": "robot",40    "data_center": "dc",41    "job": "job",42    "course": "course",43    "standard": "std",44    "funding_round": "funding",45    "acquisition": "acq",46    # infrastructure records47    "source": "src",48    "document": "doc",49    "snapshot": "snap",50    "claim": "claim",51    "relation": "rel",52    "change_event": "evt",53    "connector_run": "run",54    "queue_job": "qj",55    "llm_job": "llm",56    "review": "rev",57    "price": "price",58    "result": "res",59    "api_key": "key",60}6162ENTITY_TYPES: tuple[str, ...] = tuple(k for k in PREFIXES if k not in {63    "source", "document", "snapshot", "claim", "relation", "change_event", "connector_run", "queue_job", "llm_job",64    "review", "price", "result", "api_key"})656667def new_id(kind: str) -> str:68    prefix = PREFIXES.get(kind)69    if prefix is None:70        raise ValueError(f"unknown id kind {kind!r}")71    return f"{prefix}_{ULID()}"727374def kind_of(entity_id: str) -> str | None:75    prefix = entity_id.split("_", 1)[0]76    for kind, p in PREFIXES.items():77        if p == prefix:78            return kind79    return None808182_slug_clean = re.compile(r"[^a-z0-9.+-]+")838485def slugify(text: str, *, max_length: int = 96) -> str:86    """URL slug that keeps dots and plus signs (model names like `qwen3-8b`, `gpt-4.1`, `c++`)."""87    s = _slugify(text, lowercase=True, regex_pattern=r"[^a-z0-9.+-]+", replacements=[("/", "-"), ("_", "-"), ("@", "-at-")])88    s = _slug_clean.sub("-", s).strip("-.")89    return s[:max_length].rstrip("-.") or "item"909192def normalize_alias(text: str) -> str:93    """Deterministic alias key: lowercase, ASCII, punctuation collapsed. Used for entity resolution — never for display."""94    s = _slugify(text, lowercase=True, regex_pattern=r"[^a-z0-9]+")95    return s.replace("-", "")96