baml-py 0.89.0__cp38-abi3-manylinux_2_24_aarch64.whl → 0.90.1__cp38-abi3-manylinux_2_24_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- baml_py/baml_py.abi3.so +0 -0
- baml_py/baml_py.pyi +8 -1
- baml_py/ctx_manager.py +47 -13
- {baml_py-0.89.0.dist-info → baml_py-0.90.1.dist-info}/METADATA +1 -1
- {baml_py-0.89.0.dist-info → baml_py-0.90.1.dist-info}/RECORD +8 -8
- {baml_py-0.89.0.dist-info → baml_py-0.90.1.dist-info}/WHEEL +1 -1
- {baml_py-0.89.0.dist-info → baml_py-0.90.1.dist-info}/entry_points.txt +0 -0
- {baml_py-0.89.0.dist-info → baml_py-0.90.1.dist-info}/licenses/LICENSE +0 -0
baml_py/baml_py.abi3.so
CHANGED
Binary file
|
baml_py/baml_py.pyi
CHANGED
@@ -113,6 +113,7 @@ class BamlRuntime:
|
|
113
113
|
tb: Optional[TypeBuilder],
|
114
114
|
cr: Optional[ClientRegistry],
|
115
115
|
collectors: List[Collector],
|
116
|
+
env_vars: Dict[str, str],
|
116
117
|
) -> FunctionResult: ...
|
117
118
|
def call_function_sync(
|
118
119
|
self,
|
@@ -122,6 +123,7 @@ class BamlRuntime:
|
|
122
123
|
tb: Optional[TypeBuilder],
|
123
124
|
cr: Optional[ClientRegistry],
|
124
125
|
collectors: List[Collector],
|
126
|
+
env_vars: Dict[str, str],
|
125
127
|
) -> FunctionResult: ...
|
126
128
|
@staticmethod
|
127
129
|
def from_files(
|
@@ -139,6 +141,7 @@ class BamlRuntime:
|
|
139
141
|
tb: Optional[TypeBuilder],
|
140
142
|
cr: Optional[ClientRegistry],
|
141
143
|
collectors: List[Collector],
|
144
|
+
env_vars: Dict[str, str],
|
142
145
|
) -> FunctionResultStream: ...
|
143
146
|
def stream_function_sync(
|
144
147
|
self,
|
@@ -149,6 +152,7 @@ class BamlRuntime:
|
|
149
152
|
tb: Optional[TypeBuilder],
|
150
153
|
cr: Optional[ClientRegistry],
|
151
154
|
collectors: List[Collector],
|
155
|
+
env_vars: Dict[str, str],
|
152
156
|
) -> SyncFunctionResultStream: ...
|
153
157
|
def create_context_manager(self) -> RuntimeContextManager: ...
|
154
158
|
def flush(self) -> None: ...
|
@@ -163,6 +167,7 @@ class BamlRuntime:
|
|
163
167
|
ctx: RuntimeContextManager,
|
164
168
|
tb: Optional[TypeBuilder],
|
165
169
|
cr: Optional[ClientRegistry],
|
170
|
+
env_vars: Dict[str, str],
|
166
171
|
is_stream: bool,
|
167
172
|
) -> HTTPRequest: ...
|
168
173
|
def build_request_sync(
|
@@ -172,6 +177,7 @@ class BamlRuntime:
|
|
172
177
|
ctx: RuntimeContextManager,
|
173
178
|
tb: Optional[TypeBuilder],
|
174
179
|
cr: Optional[ClientRegistry],
|
180
|
+
env_vars: Dict[str, str],
|
175
181
|
is_stream: bool,
|
176
182
|
) -> HTTPRequest: ...
|
177
183
|
def parse_llm_response(
|
@@ -185,6 +191,7 @@ class BamlRuntime:
|
|
185
191
|
ctx: RuntimeContextManager,
|
186
192
|
tb: Optional[TypeBuilder],
|
187
193
|
cr: Optional[ClientRegistry],
|
194
|
+
env_vars: Dict[str, str],
|
188
195
|
) -> Any: ...
|
189
196
|
|
190
197
|
|
@@ -266,7 +273,7 @@ class Collector:
|
|
266
273
|
def id(self, function_log_id: str) -> Optional[FunctionLog]: ...
|
267
274
|
# For debugging
|
268
275
|
@staticmethod
|
269
|
-
def
|
276
|
+
def __function_call_count() -> int: ...
|
270
277
|
@staticmethod
|
271
278
|
def __print_storage() -> None: ...
|
272
279
|
|
baml_py/ctx_manager.py
CHANGED
@@ -5,10 +5,12 @@ import asyncio
|
|
5
5
|
import contextvars
|
6
6
|
import functools
|
7
7
|
import inspect
|
8
|
+
import os
|
8
9
|
import typing
|
9
10
|
from .baml_py import BamlLogEvent, RuntimeContextManager, BamlRuntime, BamlSpan
|
10
11
|
import atexit
|
11
12
|
import threading
|
13
|
+
from typing import Dict
|
12
14
|
|
13
15
|
F = typing.TypeVar("F", bound=typing.Callable[..., typing.Any])
|
14
16
|
|
@@ -25,11 +27,28 @@ def current_thread_id() -> int:
|
|
25
27
|
return current_thread.ident or 0
|
26
28
|
|
27
29
|
|
30
|
+
prev_ctx_manager: typing.Optional["CtxManager"] = None
|
31
|
+
|
32
|
+
|
28
33
|
class CtxManager:
|
34
|
+
def __new__(cls, *args, **kwargs):
|
35
|
+
if prev_ctx_manager is not None:
|
36
|
+
return prev_ctx_manager
|
37
|
+
return super().__new__(cls)
|
38
|
+
|
29
39
|
def __init__(self, rt: BamlRuntime):
|
40
|
+
global prev_ctx_manager
|
41
|
+
if prev_ctx_manager is not None:
|
42
|
+
self.rt = prev_ctx_manager.rt
|
43
|
+
self.ctx = prev_ctx_manager.ctx
|
44
|
+
return
|
45
|
+
|
46
|
+
prev_ctx_manager = self
|
47
|
+
|
30
48
|
self.rt = rt
|
49
|
+
|
31
50
|
self.ctx = contextvars.ContextVar[typing.Dict[int, RuntimeContextManager]](
|
32
|
-
"baml_ctx", default={
|
51
|
+
"baml_ctx", default={}
|
33
52
|
)
|
34
53
|
atexit.register(self.rt.flush)
|
35
54
|
|
@@ -70,21 +89,36 @@ class CtxManager:
|
|
70
89
|
return self.__ctx()
|
71
90
|
|
72
91
|
def start_trace_sync(
|
73
|
-
self,
|
92
|
+
self,
|
93
|
+
name: str,
|
94
|
+
args: typing.Dict[str, typing.Any],
|
95
|
+
env_vars: typing.Dict[str, str],
|
74
96
|
) -> BamlSpan:
|
97
|
+
# Clone the current context before creating the span
|
75
98
|
mng = self.__ctx()
|
76
|
-
return BamlSpan.new(self.rt, name, args, mng)
|
99
|
+
return BamlSpan.new(self.rt, name, args, mng, env_vars)
|
77
100
|
|
78
101
|
def start_trace_async(
|
79
|
-
self,
|
102
|
+
self,
|
103
|
+
name: str,
|
104
|
+
args: typing.Dict[str, typing.Any],
|
105
|
+
env_vars: typing.Dict[str, str],
|
80
106
|
) -> BamlSpan:
|
81
107
|
mng = self.__ctx()
|
82
108
|
cln = mng.deep_clone()
|
83
109
|
self.ctx.set({current_thread_id(): cln})
|
84
|
-
return BamlSpan.new(self.rt, name, args, cln)
|
110
|
+
return BamlSpan.new(self.rt, name, args, cln, env_vars)
|
85
111
|
|
86
|
-
def
|
87
|
-
|
112
|
+
def clone_context(self) -> RuntimeContextManager:
|
113
|
+
mng = self.__ctx()
|
114
|
+
cln = mng.deep_clone()
|
115
|
+
self.ctx.set({current_thread_id(): cln})
|
116
|
+
return cln
|
117
|
+
|
118
|
+
def end_trace(
|
119
|
+
self, span: BamlSpan, response: typing.Any, env_vars: typing.Dict[str, str]
|
120
|
+
) -> None:
|
121
|
+
span.finish(response, self.__ctx(), env_vars)
|
88
122
|
|
89
123
|
def flush(self) -> None:
|
90
124
|
self.rt.flush()
|
@@ -110,13 +144,13 @@ class CtxManager:
|
|
110
144
|
for i, arg in enumerate(args)
|
111
145
|
}
|
112
146
|
params.update(kwargs)
|
113
|
-
span = self.start_trace_async(func_name, params)
|
147
|
+
span = self.start_trace_async(func_name, params, os.environ.copy())
|
114
148
|
try:
|
115
149
|
response = await func(*args, **kwargs)
|
116
|
-
self.end_trace(span, response)
|
150
|
+
self.end_trace(span, response, os.environ.copy())
|
117
151
|
return response
|
118
152
|
except Exception as e:
|
119
|
-
self.end_trace(span, e)
|
153
|
+
self.end_trace(span, e, os.environ.copy())
|
120
154
|
raise e
|
121
155
|
|
122
156
|
return typing.cast(F, async_wrapper)
|
@@ -130,14 +164,14 @@ class CtxManager:
|
|
130
164
|
for i, arg in enumerate(args)
|
131
165
|
}
|
132
166
|
params.update(kwargs)
|
133
|
-
span = self.start_trace_sync(func_name, params)
|
167
|
+
span = self.start_trace_sync(func_name, params, os.environ.copy())
|
134
168
|
try:
|
135
169
|
response = func(*args, **kwargs)
|
136
|
-
self.end_trace(span, response)
|
170
|
+
self.end_trace(span, response, os.environ.copy())
|
137
171
|
return response
|
138
172
|
except Exception as e:
|
139
173
|
print("Except but ending trace!")
|
140
|
-
self.end_trace(span, e)
|
174
|
+
self.end_trace(span, e, os.environ.copy())
|
141
175
|
raise e
|
142
176
|
|
143
177
|
return typing.cast(F, wrapper)
|
@@ -1,11 +1,11 @@
|
|
1
|
-
baml_py-0.
|
2
|
-
baml_py-0.
|
3
|
-
baml_py-0.
|
4
|
-
baml_py-0.
|
1
|
+
baml_py-0.90.1.dist-info/METADATA,sha256=dfqOnYNMNtHAl8j8oo_CqkZI1KaPu5fS0WkoERvr3YI,334
|
2
|
+
baml_py-0.90.1.dist-info/WHEEL,sha256=jxb68-CzmMn8UbkjRfFQEt7fCQGUlaLj4slHZQcBCq8,107
|
3
|
+
baml_py-0.90.1.dist-info/entry_points.txt,sha256=9Uu_VcUjoI2qQMjVb0PRjEgI6pQ55WqBbzNparAPJyA,54
|
4
|
+
baml_py-0.90.1.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
|
5
5
|
baml_py/__init__.py,sha256=QWyuR-eLmqkiRW5v9RKF83knRj_HG8fyTlp6Sse9D3o,827
|
6
|
-
baml_py/baml_py.abi3.so,sha256=
|
7
|
-
baml_py/baml_py.pyi,sha256=
|
8
|
-
baml_py/ctx_manager.py,sha256=
|
6
|
+
baml_py/baml_py.abi3.so,sha256=jIw7yE-oy-4nGW5CmSurfwYcbX_dT7H9MWH3kkn0yxI,45668400
|
7
|
+
baml_py/baml_py.pyi,sha256=YYyXU1tLGLhz2OMRm9lroIAaKmQ0RZfATQ5Dea8q73s,13858
|
8
|
+
baml_py/ctx_manager.py,sha256=p6Y4X1qfUExLeBeJKcVuf4WS9NrSabjRcRFrPIasTxY,5660
|
9
9
|
baml_py/errors.py,sha256=wqv7xT_-pVXQNxD5JbOrrr_CABCFuNrLrEhmEX8RVJ8,389
|
10
10
|
baml_py/internal_monkeypatch.py,sha256=JDwBPw4S8veD3nvJ13lFw8P5p29UOmDvvkgOy8eKA58,2106
|
11
11
|
baml_py/logging.py,sha256=zM-yKPJ3LF4qpIptYQVr5zw_Gjimy3deWlTt4dOzVp0,190
|
@@ -13,4 +13,4 @@ baml_py/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
13
|
baml_py/safe_import.py,sha256=turgUpn9B4G273ZuDVjfZ_CkA2qmFQyiP-ZCPhtJO4M,2888
|
14
14
|
baml_py/stream.py,sha256=RoHvdlYi1lap7DN0sCUA-H5HtAfxxePnm1nIe6BRTTs,6892
|
15
15
|
baml_py/type_builder.py,sha256=HIAlses70C5DWNWgx3ZwsLeGt5-tviWXCXZiyyWedSg,6374
|
16
|
-
baml_py-0.
|
16
|
+
baml_py-0.90.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|