Coverage for app / db / postgres / enums.py: 100%

50 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-10-31 11:23 +0000

1from enum import StrEnum 

2 

3 

4class MessageEnum: 

5 class Role(StrEnum): 

6 SYSTEM = "system" 

7 USER = "user" 

8 ASSISTANT = "assistant" 

9 TOOL = "tool" 

10 

11 

12class ModelEnum: 

13 class Provider(StrEnum): 

14 openai = "openai" 

15 anthropic = "anthropic" 

16 google = "google" 

17 mistral = "mistral" 

18 groq = "groq" 

19 cohere = "cohere" 

20 local = "local" 

21 #: Amazon Bedrock: a model registered under it names a Bedrock model 

22 #: or inference-profile id (``inference_routes``). 

23 bedrock = "bedrock" 

24 

25 class DataRegion(StrEnum): 

26 uk = "uk" 

27 eu = "eu" 

28 us = "us" 

29 global_ = "global" 

30 

31 class Effort(StrEnum): 

32 """ 

33 How much reasoning a model brings, as a provider-independent band. 

34 

35 Providers name their tiers differently — Anthropic ships Haiku / 

36 Sonnet / Opus / Fable, OpenAI ships Luna / Terra / Sol / Astra — but 

37 the tiers line up, and what a user picking a model actually wants to 

38 say is "the cheap fast one" or "the strongest one" rather than a 

39 brand name. Recording the band makes that a filter, and makes the 

40 two catalogues comparable to each other. 

41 

42 Member names match their values deliberately: SQLAlchemy persists an 

43 enum's *name*, so a name that differs from its value is stored as 

44 something the value-side code never sees (see ``DataRegion.global_``). 

45 

46 Ordered cheapest/fastest → strongest by ``Effort.rank``. 

47 """ 

48 

49 light = "light" # Claude Haiku · GPT Luna 

50 balanced = "balanced" # Claude Sonnet · GPT Terra 

51 deep = "deep" # Claude Opus · GPT Sol 

52 frontier = "frontier" # Claude Fable · GPT Astra 

53 

54 @property 

55 def rank(self) -> int: 

56 """Position in the tier order, 0 = lightest. Lets callers compare 

57 bands ("balanced or better") without hard-coding the sequence.""" 

58 return _EFFORT_ORDER.index(self) 

59 

60 class Latency(StrEnum): 

61 """ 

62 Comparative response speed, relative to the rest of the catalogue — 

63 not a millisecond figure. Anthropic publishes exactly this band per 

64 model; OpenAI does not, so an OpenAI model takes the band its tier 

65 occupies in the same lineup. 

66 

67 Actual latency depends on prompt length, output length and reasoning 

68 effort, which is why this is a comparative band rather than a number. 

69 An observed per-model latency would come from the usage ledger; see 

70 the routing notes in ``docs/guides/governance.md``. 

71 """ 

72 

73 fastest = "fastest" 

74 fast = "fast" 

75 moderate = "moderate" 

76 slower = "slower" 

77 

78 

79# Declared outside ModelEnum.Effort: a StrEnum body cannot hold a tuple of its 

80# own members, and a class-level list would become an enum member itself. 

81_EFFORT_ORDER: tuple["ModelEnum.Effort", ...] = ( 

82 ModelEnum.Effort.light, 

83 ModelEnum.Effort.balanced, 

84 ModelEnum.Effort.deep, 

85 ModelEnum.Effort.frontier, 

86) 

87 

88 

89class InvocationEnum: 

90 class Status(StrEnum): 

91 success = "success" 

92 error = "error" 

93 timeout = "timeout" 

94 

95 

96class ToolInvocationEnum: 

97 class Status(StrEnum): 

98 success = "success" 

99 error = "error" 

100 timeout = "timeout" 

101 

102 class SourceType(StrEnum): 

103 """ 

104 Classifies the origin of a ToolCitation. 

105 

106 url — a web page (href from web_search results) 

107 document — a file/document in a knowledge base (from query_knowledge_base) 

108 other — any other citation type produced by a custom tool 

109 """ 

110 

111 url = "url" 

112 document = "document" 

113 other = "other"