model_search.py 1.3 KB

123456789101112131415161718192021222324252627282930
  1. """Picker-only search aliases for model ids."""
  2. from __future__ import annotations
  3. # Lowercased wire id → extra tokens appended to the search haystack only.
  4. _MODEL_SEARCH_ALIASES: dict[str, tuple[str, ...]] = {
  5. "k3": ("kimi-k3", "kimi"),
  6. # OpenCode Zen serves the "Ox Alpha" stealth model under an opaque
  7. # preview slug; let users find it by its public codename.
  8. "x-preview-f-free": ("ox-alpha", "ox")}
  9. # Lowercased wire id → canonical public slug (the FIRST alias by convention), so picker dedup doesn't
  10. # render a live bare id and its curated slug (``k3`` / ``kimi-k3``) as two rows.
  11. _MODEL_ALIAS_CANONICAL: dict[str, str] = {
  12. wire_id: aliases[0].lower() for wire_id, aliases in _MODEL_SEARCH_ALIASES.items() if aliases}
  13. def model_alias_canonical(model: str) -> str:
  14. """Return the canonical public slug for a bare wire-id alias."""
  15. key = (model or "").strip().lower()
  16. return _MODEL_ALIAS_CANONICAL.get(key, key)
  17. def model_search_text(model: str) -> str:
  18. """Haystack for fuzzy/substring model search; never changes the wire id sent to the provider."""
  19. mid = (model or "").strip()
  20. if not mid:
  21. return model or ""
  22. aliases = _MODEL_SEARCH_ALIASES.get(mid.lower())
  23. return f"{mid} {' '.join(aliases)}" if aliases else mid