3
3
from datetime import datetime
4
4
from typing import Any , Optional , Dict , List , Set , Union
5
5
from ell .lstr import lstr
6
- from ell .types import InvocableLM
6
+ from ell .types import InvocableLM , SerializedLMP , Invocation , SerializedLStr
7
7
8
8
9
9
class Store (ABC ):
@@ -12,111 +12,106 @@ class Store(ABC):
12
12
"""
13
13
14
14
@abstractmethod
15
- def write_lmp (self , lmp_id : str , name : str , source : str , dependencies : List [str ], is_lmp : bool , lm_kwargs : str ,
16
- version_number : int ,
17
- uses : Dict [str , Any ],
18
- commit_message : Optional [str ] = None ,
19
- created_at : Optional [datetime ]= None ) -> Optional [Any ]:
15
+ def write_lmp (self , serialized_lmp : SerializedLMP , uses : Dict [str , Any ]) -> Optional [Any ]:
20
16
"""
21
17
Write an LMP (Language Model Package) to the storage.
22
18
23
- :param lmp_id: Unique identifier for the LMP.
24
- :param name: Name of the LMP.
25
- :param source: Source code or reference for the LMP.
26
- :param dependencies: List of dependencies for the LMP.
27
- :param is_lmp: Boolean indicating if it is an LMP.
28
- :param lm_kwargs: Additional keyword arguments for the LMP.
19
+ :param serialized_lmp: SerializedLMP object containing all LMP details.
29
20
:param uses: Dictionary of LMPs used by this LMP.
30
- :param created_at: Optional timestamp of when the LMP was created.
31
21
:return: Optional return value.
32
22
"""
33
23
pass
34
24
35
25
@abstractmethod
36
- def write_invocation (self , id : str , lmp_id : str , args : str , kwargs : str , result : Union [lstr , List [lstr ]], invocation_kwargs : Dict [str , Any ],
37
- created_at : Optional [datetime ], consumes : Set [str ], prompt_tokens : Optional [int ] = None ,
38
- completion_tokens : Optional [int ] = None , latency_ms : Optional [float ] = None ,
39
- state_cache_key : Optional [str ] = None ,
40
- cost_estimate : Optional [float ] = None ) -> Optional [Any ]:
26
+ def write_invocation (self , invocation : Invocation , results : List [SerializedLStr ], consumes : Set [str ]) -> Optional [Any ]:
41
27
"""
42
28
Write an invocation of an LMP to the storage.
43
29
44
- :param id: Unique identifier for the invocation.
45
- :param lmp_id: Unique identifier for the LMP.
46
- :param args: Arguments used in the invocation.
47
- :param kwargs: Keyword arguments used in the invocation.
48
- :param result: Result of the invocation.
49
- :param invocation_kwargs: Additional keyword arguments for the invocation.
50
- :param created_at: Optional timestamp of when the invocation was created.
30
+ :param invocation: Invocation object containing all invocation details.
31
+ :param results: List of SerializedLStr objects representing the results.
51
32
:param consumes: Set of invocation IDs consumed by this invocation.
52
- :param prompt_tokens: Optional number of prompt tokens used.
53
- :param completion_tokens: Optional number of completion tokens used.
54
- :param latency_ms: Optional latency in milliseconds.
55
- :param cost_estimate: Optional estimated cost of the invocation.
56
33
:return: Optional return value.
57
34
"""
58
35
pass
59
36
60
37
@abstractmethod
61
- def get_lmps (self , ** filters : Optional [ Dict [ str , Any ]] ) -> List [Dict [ str , Any ] ]:
38
+ def get_cached_invocations (self , lmp_id : str , state_cache_key : str ) -> List [Invocation ]:
62
39
"""
63
- Retrieve LMPs from the storage.
64
-
65
- :param filters: Optional dictionary of filters to apply.
66
- :return: List of LMPs.
40
+ Get cached invocations for a given LMP and state cache key.
67
41
"""
68
42
pass
69
43
70
44
@abstractmethod
71
- def get_invocations (self , lmp_id : str , filters : Optional [ Dict [ str , Any ]] = None ) -> List [Dict [ str , Any ] ]:
45
+ def get_versions_by_fqn (self , fqn : str ) -> List [SerializedLMP ]:
72
46
"""
73
- Retrieve invocations of an LMP from the storage.
74
-
75
- :param lmp_id: Unique identifier for the LMP.
76
- :param filters: Optional dictionary of filters to apply.
77
- :return: List of invocations.
47
+ Get all versions of an LMP by its fully qualified name.
78
48
"""
79
49
pass
80
50
81
51
# @abstractmethod
82
- # def search_lmps (self, query: str) -> List[Dict[str, Any]]:
52
+ # def get_lmps (self, skip: int = 0, limit: int = 10, subquery=None, **filters: Optional[Dict[ str, Any]] ) -> List[Dict[str, Any]]:
83
53
# """
84
- # Search for LMPs in the storage.
54
+ # Retrieve LMPs from the storage.
55
+
56
+ # :param skip: Number of records to skip.
57
+ # :param limit: Maximum number of records to return.
58
+ # :param subquery: Optional subquery for filtering.
59
+ # :param filters: Optional dictionary of filters to apply.
60
+ # :return: List of LMPs.
61
+ # """
62
+ # pass
85
63
86
- # :param query: Search query string.
87
- # :return: List of LMPs matching the query.
64
+ # @abstractmethod
65
+ # def get_invocations(self, lmp_filters: Dict[str, Any], skip: int = 0, limit: int = 10, filters: Optional[Dict[str, Any]] = None, hierarchical: bool = False) -> List[Dict[str, Any]]:
66
+ # """
67
+ # Retrieve invocations of an LMP from the storage.
68
+
69
+ # :param lmp_filters: Filters to apply on the LMP level.
70
+ # :param skip: Number of records to skip.
71
+ # :param limit: Maximum number of records to return.
72
+ # :param filters: Optional dictionary of filters to apply on the invocation level.
73
+ # :param hierarchical: Whether to include hierarchical information.
74
+ # :return: List of invocations.
88
75
# """
89
76
# pass
90
77
91
78
# @abstractmethod
92
- # def search_invocations (self, query: str ) -> List[Dict[str, Any]]:
79
+ # def get_latest_lmps (self, skip: int = 0, limit: int = 10 ) -> List[Dict[str, Any]]:
93
80
# """
94
- # Search for invocations in the storage.
81
+ # Retrieve the latest versions of all LMPs from the storage.
95
82
96
- # :param query: Search query string.
97
- # :return: List of invocations matching the query.
83
+ # :param skip: Number of records to skip.
84
+ # :param limit: Maximum number of records to return.
85
+ # :return: List of the latest LMPs.
98
86
# """
99
87
# pass
100
88
89
+ # @abstractmethod
90
+ # def get_traces(self) -> List[Dict[str, Any]]:
91
+ # """
92
+ # Retrieve all traces from the storage.
101
93
102
- @abstractmethod
103
- def get_latest_lmps (self ) -> List [Dict [str , Any ]]:
104
- """
105
- Retrieve the latest versions of all LMPs from the storage.
94
+ # :return: List of traces.
95
+ # """
96
+ # pass
106
97
107
- :return: List of the latest LMPs.
108
- """
109
- pass
98
+ # @abstractmethod
99
+ # def get_all_traces_leading_to(self, invocation_id: str) -> List[Dict[str, Any]]:
100
+ # """
101
+ # Retrieve all traces leading to a specific invocation.
110
102
103
+ # :param invocation_id: ID of the invocation to trace.
104
+ # :return: List of traces leading to the specified invocation.
105
+ # """
106
+ # pass
111
107
112
108
@contextmanager
113
109
def freeze (self , * lmps : InvocableLM ):
114
110
"""
115
111
A context manager for caching operations using a particular store.
116
112
117
113
Args:
118
- key (Optional[str]): The cache key. If None, a default key will be generated.
119
- condition (Optional[Callable[..., bool]]): A function that determines whether to cache or not.
114
+ *lmps: InvocableLM objects to freeze.
120
115
121
116
Yields:
122
117
None
0 commit comments