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

39 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-06-28 01:01 +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.""" 

57 

58 SMALL = "small" 

59 MEDIUM = "medium" 

60 LARGE = "large" 

61 

62 

63class CatalogSort(StrEnum): 

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

65 

66 FEATURED = "featured" 

67 DOWNLOADS = "downloads" 

68 NAME = "name" 

69 SIZE_ASC = "size_asc" 

70 SIZE_DESC = "size_desc" 

71 

72 

73class ModelCompat(StrEnum): 

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

75 

76 SUPPORTED = "supported" 

77 UNSUPPORTED = "unsupported" 

78 UNKNOWN = "unknown"