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

19 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-05-15 20:55 +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 

29 @classmethod 

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

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

32 

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

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

35 """ 

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

37 return None 

38 try: 

39 return cls(value) 

40 except ValueError as exc: 

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

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