payi 0.1.0a131__py3-none-any.whl → 0.1.0a133__py3-none-any.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.
Potentially problematic release.
This version of payi might be problematic. Click here for more details.
- payi/_streaming.py +4 -6
- payi/_version.py +1 -1
- payi/lib/instrument.py +42 -3
- {payi-0.1.0a131.dist-info → payi-0.1.0a133.dist-info}/METADATA +1 -1
- {payi-0.1.0a131.dist-info → payi-0.1.0a133.dist-info}/RECORD +7 -7
- {payi-0.1.0a131.dist-info → payi-0.1.0a133.dist-info}/WHEEL +0 -0
- {payi-0.1.0a131.dist-info → payi-0.1.0a133.dist-info}/licenses/LICENSE +0 -0
payi/_streaming.py
CHANGED
|
@@ -57,9 +57,8 @@ class Stream(Generic[_T]):
|
|
|
57
57
|
for sse in iterator:
|
|
58
58
|
yield process_data(data=sse.json(), cast_to=cast_to, response=response)
|
|
59
59
|
|
|
60
|
-
#
|
|
61
|
-
|
|
62
|
-
...
|
|
60
|
+
# As we might not fully consume the response stream, we need to close it explicitly
|
|
61
|
+
response.close()
|
|
63
62
|
|
|
64
63
|
def __enter__(self) -> Self:
|
|
65
64
|
return self
|
|
@@ -121,9 +120,8 @@ class AsyncStream(Generic[_T]):
|
|
|
121
120
|
async for sse in iterator:
|
|
122
121
|
yield process_data(data=sse.json(), cast_to=cast_to, response=response)
|
|
123
122
|
|
|
124
|
-
#
|
|
125
|
-
|
|
126
|
-
...
|
|
123
|
+
# As we might not fully consume the response stream, we need to close it explicitly
|
|
124
|
+
await response.aclose()
|
|
127
125
|
|
|
128
126
|
async def __aenter__(self) -> Self:
|
|
129
127
|
return self
|
payi/_version.py
CHANGED
payi/lib/instrument.py
CHANGED
|
@@ -6,6 +6,7 @@ import atexit
|
|
|
6
6
|
import asyncio
|
|
7
7
|
import inspect
|
|
8
8
|
import logging
|
|
9
|
+
import threading
|
|
9
10
|
import traceback
|
|
10
11
|
from abc import abstractmethod
|
|
11
12
|
from enum import Enum
|
|
@@ -210,6 +211,15 @@ class _StreamingType(Enum):
|
|
|
210
211
|
iterator = 1
|
|
211
212
|
stream_manager = 2
|
|
212
213
|
|
|
214
|
+
class _ThreadLocalContextStorage(threading.local):
|
|
215
|
+
"""
|
|
216
|
+
Thread-local storage for context stacks. Each thread gets its own context stack.
|
|
217
|
+
|
|
218
|
+
Note: We don't use __init__ because threading.local's __init__ semantics are tricky.
|
|
219
|
+
Instead, we lazily initialize the context_stack attribute in the property accessor.
|
|
220
|
+
"""
|
|
221
|
+
context_stack: "list[_Context]"
|
|
222
|
+
|
|
213
223
|
class _InternalTrackContext:
|
|
214
224
|
def __init__(
|
|
215
225
|
self,
|
|
@@ -256,7 +266,12 @@ class _PayiInstrumentor:
|
|
|
256
266
|
if self._apayi:
|
|
257
267
|
_g_logger.debug(f"Pay-i instrumentor initialized with AsyncPayi instance: {self._apayi}")
|
|
258
268
|
|
|
259
|
-
|
|
269
|
+
# Thread-local storage for context stacks - each thread gets its own stack
|
|
270
|
+
self._thread_local_storage = _ThreadLocalContextStorage()
|
|
271
|
+
|
|
272
|
+
# Global immutable initial context that all threads inherit on first access
|
|
273
|
+
self._global_initial_context: Optional[_Context] = None
|
|
274
|
+
|
|
260
275
|
self._log_prompt_and_response: bool = log_prompt_and_response
|
|
261
276
|
|
|
262
277
|
self._blocked_limits: set[str] = set()
|
|
@@ -316,7 +331,7 @@ class _PayiInstrumentor:
|
|
|
316
331
|
|
|
317
332
|
self.__enter__()
|
|
318
333
|
|
|
319
|
-
# _init_current_context will update the
|
|
334
|
+
# _init_current_context will update the current context stack location
|
|
320
335
|
context: _Context = {}
|
|
321
336
|
# Copy allowed keys from global_config into context
|
|
322
337
|
# Dynamically use keys from _Context TypedDict
|
|
@@ -325,7 +340,12 @@ class _PayiInstrumentor:
|
|
|
325
340
|
if key in global_config:
|
|
326
341
|
context[key] = global_config[key] # type: ignore
|
|
327
342
|
|
|
328
|
-
self._init_current_context(**context)
|
|
343
|
+
self._init_current_context(**context)
|
|
344
|
+
|
|
345
|
+
# Store the initialized context as the global initial context (immutable after this point)
|
|
346
|
+
# All threads will inherit a copy of this context on their first access
|
|
347
|
+
current_context = self.get_context()
|
|
348
|
+
self._global_initial_context = current_context.copy() if current_context else None
|
|
329
349
|
|
|
330
350
|
def _ensure_payi_clients(self) -> None:
|
|
331
351
|
if self._offline_instrumentation is not None:
|
|
@@ -689,6 +709,25 @@ class _PayiInstrumentor:
|
|
|
689
709
|
def _ingest_units(self, request: _ProviderRequest) -> Optional[Union[XproxyResult, XproxyError]]:
|
|
690
710
|
return self.set_xproxy_result(self._ingest_units_worker(request))
|
|
691
711
|
|
|
712
|
+
@property
|
|
713
|
+
def _context_stack(self) -> "list[_Context]":
|
|
714
|
+
"""
|
|
715
|
+
Get the thread-local context stack. On first access per thread,
|
|
716
|
+
initializes with the global initial context if one was set.
|
|
717
|
+
"""
|
|
718
|
+
# Lazy-initialize the context_stack for this thread if it doesn't exist
|
|
719
|
+
if not hasattr(self._thread_local_storage, 'context_stack'):
|
|
720
|
+
self._thread_local_storage.context_stack = []
|
|
721
|
+
|
|
722
|
+
stack = self._thread_local_storage.context_stack
|
|
723
|
+
|
|
724
|
+
# If this is the first access in this thread and we have a global initial context,
|
|
725
|
+
# initialize this thread's stack with it
|
|
726
|
+
if len(stack) == 0 and self._global_initial_context is not None:
|
|
727
|
+
stack.append(self._global_initial_context.copy())
|
|
728
|
+
|
|
729
|
+
return stack
|
|
730
|
+
|
|
692
731
|
def _setup_call_func(
|
|
693
732
|
self
|
|
694
733
|
) -> _Context:
|
|
@@ -9,9 +9,9 @@ payi/_models.py,sha256=lKnskYPONAWDvWo8tmbbVk7HmG7UOsI0Nve0vSMmkRc,30452
|
|
|
9
9
|
payi/_qs.py,sha256=craIKyvPktJ94cvf9zn8j8ekG9dWJzhWv0ob34lIOv4,4828
|
|
10
10
|
payi/_resource.py,sha256=j2jIkTr8OIC8sU6-05nxSaCyj4MaFlbZrwlyg4_xJos,1088
|
|
11
11
|
payi/_response.py,sha256=rh9oJAvCKcPwQFm4iqH_iVrmK8bNx--YP_A2a4kN1OU,28776
|
|
12
|
-
payi/_streaming.py,sha256=
|
|
12
|
+
payi/_streaming.py,sha256=r-qd1jFI1Df33CEelGocyNFdGg4C_NAK8TEX9GmxdOM,10141
|
|
13
13
|
payi/_types.py,sha256=d6xrZDG6rG6opphTN7UVYdEOis3977LrQQgpNtklXZE,7234
|
|
14
|
-
payi/_version.py,sha256=
|
|
14
|
+
payi/_version.py,sha256=kw_Cm8vm327o_bU7L7yyNX5kwwFwX2nVPCsToTbFc6g,166
|
|
15
15
|
payi/pagination.py,sha256=k2356QGPOUSjRF2vHpwLBdF6P-2vnQzFfRIJQAHGQ7A,1258
|
|
16
16
|
payi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
17
|
payi/_utils/__init__.py,sha256=7fch0GT9zpNnErbciSpUNa-SjTxxjY6kxHxKMOM4AGs,2305
|
|
@@ -35,7 +35,7 @@ payi/lib/Stopwatch.py,sha256=7OJlxvr2Jyb6Zr1LYCYKczRB7rDVKkIR7gc4YoleNdE,764
|
|
|
35
35
|
payi/lib/VertexInstrumentor.py,sha256=OWuMPiW4LdLhj6DSAAy5qZiosVo8DSAuFWGxYpEucoE,7431
|
|
36
36
|
payi/lib/VertexRequest.py,sha256=42F7xCRYY6h3EMUZD1x4-_cwyAcVhnzT9M5zl4KwtE0,11801
|
|
37
37
|
payi/lib/helpers.py,sha256=6c0RFMS0AYVIxU6q8ak1CDwMTwldIN7N2O2XkxTO7ag,4931
|
|
38
|
-
payi/lib/instrument.py,sha256=
|
|
38
|
+
payi/lib/instrument.py,sha256=Mc9ipigz21qvuM6tWC1GoYSr-zoJDBrGmxZm6DxqCbo,78765
|
|
39
39
|
payi/lib/version_helper.py,sha256=v0lC3kuaXn6PBDolE3mkmwJiA8Ot3z4RkVR7wlBuZCs,540
|
|
40
40
|
payi/lib/data/cohere_embed_english_v3.json,sha256=YEWwjml3_i16cdsOx_7UKe6xpVFnxTEhP8T1n54R6gY,718306
|
|
41
41
|
payi/resources/__init__.py,sha256=B2bn1ZfCf6TbHlzZvy5TpFPtALnFcBRPYVKQH3S5qfQ,2457
|
|
@@ -135,7 +135,7 @@ payi/types/use_cases/definitions/kpi_retrieve_response.py,sha256=uQXliSvS3k-yDYw
|
|
|
135
135
|
payi/types/use_cases/definitions/kpi_update_params.py,sha256=jbawdWAdMnsTWVH0qfQGb8W7_TXe3lq4zjSRu44d8p8,373
|
|
136
136
|
payi/types/use_cases/definitions/kpi_update_response.py,sha256=zLyEoT0S8d7XHsnXZYT8tM7yDw0Aze0Mk-_Z6QeMtc8,459
|
|
137
137
|
payi/types/use_cases/definitions/limit_config_create_params.py,sha256=Y6RR7IYiTZHYJ4y6m2TmlAe4ArtbjEl7fIrAhnCvuPI,464
|
|
138
|
-
payi-0.1.
|
|
139
|
-
payi-0.1.
|
|
140
|
-
payi-0.1.
|
|
141
|
-
payi-0.1.
|
|
138
|
+
payi-0.1.0a133.dist-info/METADATA,sha256=Y0bDz9gEnpdYXh7hMvgRGnnJ632FAYiKf4bnv1Fq6-c,16324
|
|
139
|
+
payi-0.1.0a133.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
140
|
+
payi-0.1.0a133.dist-info/licenses/LICENSE,sha256=CQt03aM-P4a3Yg5qBg3JSLVoQS3smMyvx7tYg_6V7Gk,11334
|
|
141
|
+
payi-0.1.0a133.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|