Coverage for src/lilbee/catalog/types.py: 100%

40 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-08-14 11:46 +0000

1"""Domain enums for model task and source classification.""" 

2 

3from __future__ import annotations 

4 

5from enum import StrEnum 

6 

7 

8class ModelTask(StrEnum): 

9 """Task classification for models.""" 

10 

11 CHAT = "chat" 

12 EMBEDDING = "embedding" 

13 VISION = "vision" 

14 RERANK = "rerank" 

15 

16 

17class ModelSource(StrEnum): 

18 """Where a model is stored. 

19 

20 StrEnum (not Enum) so ``ModelSource.NATIVE == "native"`` is True at 

21 runtime. Pre-existing tests, JSON-decoded payloads from older clients, 

22 and server handler comparisons against bare strings keep working 

23 without an explicit ``.value`` lookup or enum import. 

24 """ 

25 

26 NATIVE = "native" # lilbee's GGUF files in cfg.models_dir 

27 REMOTE = "remote" # Models managed by a remote SDK-backed service 

28 FRONTIER = "frontier" # Cloud API-key models (Gemini/OpenAI/Anthropic/…) 

29 OLLAMA = "ollama" # Models served by a reachable Ollama endpoint 

30 LM_STUDIO = "lm_studio" # Models served by a reachable LM Studio endpoint 

31 

32 @classmethod 

33 def parse(cls, value: str | None) -> ModelSource | None: 

34 """Parse a user-supplied source string. Empty or None means 'all'. 

35 

36 Raises ValueError on any other non-empty input so callers get a 

37 consistent error type regardless of entry point (CLI, MCP, server). 

38 """ 

39 if value is None or value == "": 

40 return None 

41 try: 

42 return cls(value) 

43 except ValueError as exc: 

44 valid = ", ".join(s.value for s in cls) 

45 raise ValueError(f"invalid source {value!r}; expected one of: {valid}") from exc 

46 

47 

48class KeyStatus(StrEnum): 

49 """Whether a hosted provider's API key is configured.""" 

50 

51 READY = "ready" 

52 MISSING_KEY = "missing_key" 

53 

54 

55class CatalogSize(StrEnum): 

56 """Size bucket for catalog filtering, keyed on parameter count. 

57 

58 Not named ``FRONTIER`` at the top end: ``CatalogRowKind.FRONTIER`` already 

59 means cloud API-key models, the opposite side of the local/remote split. 

60 """ 

61 

62 SMALL = "small" 

63 MEDIUM = "medium" 

64 LARGE = "large" 

65 HUGE = "huge" 

66 

67 

68class CatalogSort(StrEnum): 

69 """Sort key for catalog browse results.""" 

70 

71 FEATURED = "featured" 

72 DOWNLOADS = "downloads" 

73 NAME = "name" 

74 SIZE_ASC = "size_asc" 

75 SIZE_DESC = "size_desc" 

76 

77 

78class ModelCompat(StrEnum): 

79 """Whether the bundled llama.cpp runtime supports a model's architecture.""" 

80 

81 SUPPORTED = "supported" 

82 UNSUPPORTED = "unsupported" 

83 UNKNOWN = "unknown"