Coverage for /home/admin/Documents/AI/applications/lexigram-dev/lexigram/experimental/ai/lexigram-ai-llm/src/lexigram/ai/llm/protocols.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-25 07:19 +0800

1"""LLM-specific protocols owned by lexigram-ai-llm.""" 

2 

3from __future__ import annotations 

4 

5from typing import Any, Protocol, runtime_checkable 

6 

7 

8@runtime_checkable 

9class LLMCacheProtocol(Protocol): 

10 """Protocol for LLM cache implementations.""" 

11 

12 async def get(self, key: str | dict[str, Any]) -> Any | None: 

13 """Get value from cache. 

14 

15 Args: 

16 key: Cache key (string or structured dict). 

17 

18 Returns: 

19 Cached value, or ``None`` if not present. 

20 """ 

21 ... 

22 

23 async def set( 

24 self, 

25 key: str | dict[str, Any], 

26 value: Any, 

27 ttl: float | None = None, 

28 ) -> None: 

29 """Set value in cache. 

30 

31 Args: 

32 key: Cache key (string or structured dict). 

33 value: Value to store. 

34 ttl: Optional time-to-live in seconds. 

35 """ 

36 ... 

37 

38 async def delete(self, key: str | dict[str, Any]) -> bool: 

39 """Delete entry from cache. 

40 

41 Args: 

42 key: Cache key to remove. 

43 

44 Returns: 

45 ``True`` if the key existed and was removed, ``False`` otherwise. 

46 """ 

47 ... 

48 

49 async def clear(self) -> None: 

50 """Clear all entries.""" 

51 ... 

52 

53 def get_stats(self) -> dict[str, Any]: 

54 """Return cache statistics. 

55 

56 Returns: 

57 Mapping of statistic name to value. 

58 """ 

59 ... 

60 

61 

62__all__ = ["LLMCacheProtocol"]