payi 0.1.0a62__py3-none-any.whl → 0.1.0a64__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/_utils/_transform.py +22 -0
- payi/_version.py +1 -1
- payi/lib/helpers.py +3 -0
- payi/lib/instrument.py +151 -180
- {payi-0.1.0a62.dist-info → payi-0.1.0a64.dist-info}/METADATA +1 -1
- {payi-0.1.0a62.dist-info → payi-0.1.0a64.dist-info}/RECORD +8 -8
- {payi-0.1.0a62.dist-info → payi-0.1.0a64.dist-info}/WHEEL +0 -0
- {payi-0.1.0a62.dist-info → payi-0.1.0a64.dist-info}/licenses/LICENSE +0 -0
payi/_utils/_transform.py
CHANGED
|
@@ -142,6 +142,10 @@ def _maybe_transform_key(key: str, type_: type) -> str:
|
|
|
142
142
|
return key
|
|
143
143
|
|
|
144
144
|
|
|
145
|
+
def _no_transform_needed(annotation: type) -> bool:
|
|
146
|
+
return annotation == float or annotation == int
|
|
147
|
+
|
|
148
|
+
|
|
145
149
|
def _transform_recursive(
|
|
146
150
|
data: object,
|
|
147
151
|
*,
|
|
@@ -184,6 +188,15 @@ def _transform_recursive(
|
|
|
184
188
|
return cast(object, data)
|
|
185
189
|
|
|
186
190
|
inner_type = extract_type_arg(stripped_type, 0)
|
|
191
|
+
if _no_transform_needed(inner_type):
|
|
192
|
+
# for some types there is no need to transform anything, so we can get a small
|
|
193
|
+
# perf boost from skipping that work.
|
|
194
|
+
#
|
|
195
|
+
# but we still need to convert to a list to ensure the data is json-serializable
|
|
196
|
+
if is_list(data):
|
|
197
|
+
return data
|
|
198
|
+
return list(data)
|
|
199
|
+
|
|
187
200
|
return [_transform_recursive(d, annotation=annotation, inner_type=inner_type) for d in data]
|
|
188
201
|
|
|
189
202
|
if is_union_type(stripped_type):
|
|
@@ -332,6 +345,15 @@ async def _async_transform_recursive(
|
|
|
332
345
|
return cast(object, data)
|
|
333
346
|
|
|
334
347
|
inner_type = extract_type_arg(stripped_type, 0)
|
|
348
|
+
if _no_transform_needed(inner_type):
|
|
349
|
+
# for some types there is no need to transform anything, so we can get a small
|
|
350
|
+
# perf boost from skipping that work.
|
|
351
|
+
#
|
|
352
|
+
# but we still need to convert to a list to ensure the data is json-serializable
|
|
353
|
+
if is_list(data):
|
|
354
|
+
return data
|
|
355
|
+
return list(data)
|
|
356
|
+
|
|
335
357
|
return [await _async_transform_recursive(d, annotation=annotation, inner_type=inner_type) for d in data]
|
|
336
358
|
|
|
337
359
|
if is_union_type(stripped_type):
|
payi/_version.py
CHANGED
payi/lib/helpers.py
CHANGED
|
@@ -49,6 +49,7 @@ def create_headers(
|
|
|
49
49
|
use_case_id: Union[str, None] = None,
|
|
50
50
|
use_case_name: Union[str, None] = None,
|
|
51
51
|
use_case_version: Union[int, None] = None,
|
|
52
|
+
route_as_resource: Union[str, None] = None,
|
|
52
53
|
) -> Dict[str, str]:
|
|
53
54
|
headers: Dict[str, str] = {}
|
|
54
55
|
|
|
@@ -68,6 +69,8 @@ def create_headers(
|
|
|
68
69
|
headers.update({ PayiHeaderNames.use_case_name: use_case_name})
|
|
69
70
|
if use_case_version:
|
|
70
71
|
headers.update({ PayiHeaderNames.use_case_version: str(use_case_version)})
|
|
72
|
+
if route_as_resource:
|
|
73
|
+
headers.update({ PayiHeaderNames.route_as_resource: route_as_resource})
|
|
71
74
|
return headers
|
|
72
75
|
|
|
73
76
|
def _resolve_payi_base_url(payi_base_url: Union[str, None]) -> str:
|
payi/lib/instrument.py
CHANGED
|
@@ -23,8 +23,8 @@ from .Stopwatch import Stopwatch
|
|
|
23
23
|
|
|
24
24
|
class PayiInstrumentConfig(TypedDict, total=False):
|
|
25
25
|
proxy: bool
|
|
26
|
+
global_instrumentation_enabled: bool
|
|
26
27
|
limit_ids: Optional["list[str]"]
|
|
27
|
-
request_tags: Optional["list[str]"]
|
|
28
28
|
experience_name: Optional[str]
|
|
29
29
|
experience_id: Optional[str]
|
|
30
30
|
use_case_name: Optional[str]
|
|
@@ -40,18 +40,8 @@ class _Context(TypedDict, total=False):
|
|
|
40
40
|
use_case_id: Optional[str]
|
|
41
41
|
use_case_version: Optional[int]
|
|
42
42
|
limit_ids: Optional['list[str]']
|
|
43
|
-
request_tags: Optional['list[str]']
|
|
44
43
|
user_id: Optional[str]
|
|
45
44
|
|
|
46
|
-
class _ParentState(TypedDict, total=False):
|
|
47
|
-
experience_name: Optional[str]
|
|
48
|
-
experience_id: Optional[str]
|
|
49
|
-
use_case_name: Optional[str]
|
|
50
|
-
use_case_id: Optional[str]
|
|
51
|
-
use_case_version: Optional[int]
|
|
52
|
-
limit_ids: Optional['list[str]']
|
|
53
|
-
request_tags: Optional['list[str]']
|
|
54
|
-
|
|
55
45
|
class _IsStreaming(Enum):
|
|
56
46
|
false = 0
|
|
57
47
|
true = 1
|
|
@@ -69,14 +59,11 @@ class _PayiInstrumentor:
|
|
|
69
59
|
prompt_and_response_logger: Optional[
|
|
70
60
|
Callable[[str, "dict[str, str]"], None]
|
|
71
61
|
] = None, # (request id, dict of data to store) -> None
|
|
62
|
+
global_config: Optional[PayiInstrumentConfig] = None,
|
|
72
63
|
):
|
|
73
64
|
self._payi: Optional[Payi] = payi
|
|
74
65
|
self._apayi: Optional[AsyncPayi] = apayi
|
|
75
66
|
|
|
76
|
-
if not self._payi and not self._apayi:
|
|
77
|
-
self._payi = Payi()
|
|
78
|
-
self._apayi = AsyncPayi()
|
|
79
|
-
|
|
80
67
|
self._context_stack: list[_Context] = [] # Stack of context dictionaries
|
|
81
68
|
self._log_prompt_and_response: bool = log_prompt_and_response
|
|
82
69
|
self._prompt_and_response_logger: Optional[Callable[[str, dict[str, str]], None]] = prompt_and_response_logger
|
|
@@ -89,6 +76,24 @@ class _PayiInstrumentor:
|
|
|
89
76
|
else:
|
|
90
77
|
self._instrument_specific(instruments)
|
|
91
78
|
|
|
79
|
+
global_instrumentation_enabled = global_config.pop("global_instrumentation_enabled", True) if global_config else True
|
|
80
|
+
|
|
81
|
+
if global_instrumentation_enabled:
|
|
82
|
+
if global_config is None:
|
|
83
|
+
global_config = {}
|
|
84
|
+
if "proxy" not in global_config:
|
|
85
|
+
global_config["proxy"] = False
|
|
86
|
+
|
|
87
|
+
# Use default clients if not provided for global ingest instrumentation
|
|
88
|
+
if not self._payi and not self._apayi and global_config.get("proxy") == False:
|
|
89
|
+
self._payi = Payi()
|
|
90
|
+
self._apayi = AsyncPayi()
|
|
91
|
+
|
|
92
|
+
context: _Context = {}
|
|
93
|
+
self._context_stack.append(context)
|
|
94
|
+
# init_context will update the currrent context stack location
|
|
95
|
+
self._init_context(context=context, parentContext={}, **global_config) # type: ignore
|
|
96
|
+
|
|
92
97
|
def _instrument_all(self) -> None:
|
|
93
98
|
self._instrument_openai()
|
|
94
99
|
self._instrument_anthropic()
|
|
@@ -249,90 +254,99 @@ class _PayiInstrumentor:
|
|
|
249
254
|
|
|
250
255
|
def _setup_call_func(
|
|
251
256
|
self
|
|
252
|
-
) -> 'tuple[_Context,
|
|
257
|
+
) -> 'tuple[_Context, _Context]':
|
|
253
258
|
context: _Context = {}
|
|
254
|
-
|
|
259
|
+
parentContext: _Context = {}
|
|
255
260
|
|
|
256
261
|
if len(self._context_stack) > 0:
|
|
257
262
|
# copy current context into the upcoming context
|
|
258
263
|
context = self._context_stack[-1].copy()
|
|
259
264
|
context.pop("proxy")
|
|
260
|
-
|
|
261
|
-
parentState["experience_id"] = context.get("experience_id", None)
|
|
262
|
-
parentState["use_case_name"] = context.get("use_case_name", None)
|
|
263
|
-
parentState["use_case_id"] = context.get("use_case_id", None)
|
|
264
|
-
parentState["use_case_version"] = context.get("use_case_version", None)
|
|
265
|
-
parentState["limit_ids"] = context.get("limit_ids", None)
|
|
266
|
-
parentState["request_tags"] = context.get("request_tags", None)
|
|
265
|
+
parentContext = {**context}
|
|
267
266
|
|
|
268
|
-
return (context,
|
|
267
|
+
return (context, parentContext)
|
|
269
268
|
|
|
270
269
|
def _init_context(
|
|
271
270
|
self,
|
|
272
271
|
context: _Context,
|
|
273
|
-
|
|
272
|
+
parentContext: _Context,
|
|
274
273
|
proxy: bool,
|
|
275
|
-
limit_ids: Optional["list[str]"],
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
user_id: Optional[str],
|
|
274
|
+
limit_ids: Optional["list[str]"] = None,
|
|
275
|
+
experience_name: Optional[str] = None,
|
|
276
|
+
experience_id: Optional[str] = None,
|
|
277
|
+
use_case_name: Optional[str]= None,
|
|
278
|
+
use_case_id: Optional[str]= None,
|
|
279
|
+
use_case_version: Optional[int]= None,
|
|
280
|
+
user_id: Optional[str]= None,
|
|
283
281
|
) -> None:
|
|
284
282
|
context["proxy"] = proxy
|
|
285
283
|
|
|
286
|
-
|
|
284
|
+
parent_experience_name = parentContext.get("experience_name", None)
|
|
285
|
+
parent_experience_id = parentContext.get("experience_id", None)
|
|
287
286
|
|
|
288
|
-
|
|
289
|
-
if not experience_name:
|
|
287
|
+
if experience_name is None:
|
|
290
288
|
# If no experience_name specified, use previous values
|
|
291
|
-
context["experience_name"] =
|
|
292
|
-
context["experience_id"] =
|
|
289
|
+
context["experience_name"] = parent_experience_name
|
|
290
|
+
context["experience_id"] = parent_experience_id
|
|
291
|
+
elif len(experience_name) == 0:
|
|
292
|
+
# Empty string explicitly blocks inheriting from the parent state
|
|
293
|
+
context["experience_name"] = None
|
|
294
|
+
context["experience_id"] = None
|
|
293
295
|
else:
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
# If experience_name is specified
|
|
298
|
-
if experience_name == previous_experience_name:
|
|
296
|
+
# Check if experience_name is the same as the previous one
|
|
297
|
+
if experience_name == parent_experience_name:
|
|
299
298
|
# Same experience name, use previous ID unless new one specified
|
|
300
299
|
context["experience_name"] = experience_name
|
|
301
|
-
context["experience_id"] = experience_id if experience_id else
|
|
300
|
+
context["experience_id"] = experience_id if experience_id else parent_experience_id
|
|
302
301
|
else:
|
|
303
302
|
# Different experience name, use specified ID or generate one
|
|
304
303
|
context["experience_name"] = experience_name
|
|
305
304
|
context["experience_id"] = experience_id if experience_id else str(uuid.uuid4())
|
|
306
305
|
|
|
307
|
-
|
|
308
|
-
|
|
306
|
+
parent_use_case_name = parentContext.get("use_case_name", None)
|
|
307
|
+
parent_use_case_id = parentContext.get("use_case_id", None)
|
|
308
|
+
parent_use_case_version = parentContext.get("use_case_version", None)
|
|
309
|
+
|
|
310
|
+
if use_case_name is None:
|
|
309
311
|
# If no use_case_name specified, use previous values
|
|
310
|
-
context["use_case_name"] =
|
|
311
|
-
context["use_case_id"] =
|
|
312
|
-
context["use_case_version"] =
|
|
312
|
+
context["use_case_name"] = parent_use_case_name
|
|
313
|
+
context["use_case_id"] = parent_use_case_id
|
|
314
|
+
context["use_case_version"] = parent_use_case_version
|
|
315
|
+
elif len(use_case_name) == 0:
|
|
316
|
+
# Empty string explicitly blocks inheriting from the parent state
|
|
317
|
+
context["use_case_name"] = None
|
|
318
|
+
context["use_case_id"] = None
|
|
319
|
+
context["use_case_version"] = None
|
|
313
320
|
else:
|
|
314
|
-
|
|
315
|
-
previous_use_case_id = parentState.get("use_case_id", None)
|
|
316
|
-
previous_use_case_version = parentState.get("use_case_version", None)
|
|
317
|
-
|
|
318
|
-
# If use_case_name is specified
|
|
319
|
-
if use_case_name == previous_use_case_name:
|
|
321
|
+
if use_case_name == parent_use_case_name:
|
|
320
322
|
# Same use case name, use previous ID unless new one specified
|
|
321
323
|
context["use_case_name"] = use_case_name
|
|
322
|
-
context["use_case_id"] = use_case_id if use_case_id else
|
|
323
|
-
context["use_case_version"] = use_case_version if use_case_version else
|
|
324
|
+
context["use_case_id"] = use_case_id if use_case_id else parent_use_case_id
|
|
325
|
+
context["use_case_version"] = use_case_version if use_case_version else parent_use_case_version
|
|
324
326
|
else:
|
|
325
|
-
# Different
|
|
327
|
+
# Different use case name, use specified ID or generate one
|
|
326
328
|
context["use_case_name"] = use_case_name
|
|
327
329
|
context["use_case_id"] = use_case_id if use_case_id else str(uuid.uuid4())
|
|
328
|
-
context["use_case_version"] = use_case_version
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
if limit_ids:
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
330
|
+
context["use_case_version"] = use_case_version if use_case_version else None
|
|
331
|
+
|
|
332
|
+
parent_limit_ids = parentContext.get("limit_ids", None)
|
|
333
|
+
if limit_ids is None:
|
|
334
|
+
# use the parent limit_ids if it exists
|
|
335
|
+
context["limit_ids"] = parent_limit_ids
|
|
336
|
+
elif len(limit_ids) == 0:
|
|
337
|
+
# caller passing an empty array explicitly blocks inheriting from the parent state
|
|
338
|
+
context["limit_ids"] = None
|
|
339
|
+
else:
|
|
340
|
+
# union of new and parent lists if the parent context contains limit ids
|
|
341
|
+
context["limit_ids"] = list(set(limit_ids) | set(parent_limit_ids)) if parent_limit_ids else limit_ids
|
|
342
|
+
|
|
343
|
+
if user_id is None:
|
|
344
|
+
# use the parent user_id if it exists
|
|
345
|
+
context["user_id"] = parentContext.get("user_id", None)
|
|
346
|
+
elif len(user_id) == 0:
|
|
347
|
+
# caller passing an empty string explicitly blocks inheriting from the parent state
|
|
348
|
+
context["user_id"] = None
|
|
349
|
+
else:
|
|
336
350
|
context["user_id"] = user_id
|
|
337
351
|
|
|
338
352
|
self.set_context(context)
|
|
@@ -342,7 +356,6 @@ class _PayiInstrumentor:
|
|
|
342
356
|
func: Any,
|
|
343
357
|
proxy: bool,
|
|
344
358
|
limit_ids: Optional["list[str]"],
|
|
345
|
-
request_tags: Optional["list[str]"],
|
|
346
359
|
experience_name: Optional[str],
|
|
347
360
|
experience_id: Optional[str],
|
|
348
361
|
use_case_name: Optional[str],
|
|
@@ -352,15 +365,14 @@ class _PayiInstrumentor:
|
|
|
352
365
|
*args: Any,
|
|
353
366
|
**kwargs: Any,
|
|
354
367
|
) -> Any:
|
|
355
|
-
context,
|
|
368
|
+
context, parentContext = self._setup_call_func()
|
|
356
369
|
|
|
357
370
|
with self:
|
|
358
371
|
self._init_context(
|
|
359
372
|
context,
|
|
360
|
-
|
|
373
|
+
parentContext,
|
|
361
374
|
proxy,
|
|
362
375
|
limit_ids,
|
|
363
|
-
request_tags,
|
|
364
376
|
experience_name,
|
|
365
377
|
experience_id,
|
|
366
378
|
use_case_name,
|
|
@@ -374,7 +386,6 @@ class _PayiInstrumentor:
|
|
|
374
386
|
func: Any,
|
|
375
387
|
proxy: bool,
|
|
376
388
|
limit_ids: Optional["list[str]"],
|
|
377
|
-
request_tags: Optional["list[str]"],
|
|
378
389
|
experience_name: Optional[str],
|
|
379
390
|
experience_id: Optional[str],
|
|
380
391
|
use_case_name: Optional[str],
|
|
@@ -384,15 +395,14 @@ class _PayiInstrumentor:
|
|
|
384
395
|
*args: Any,
|
|
385
396
|
**kwargs: Any,
|
|
386
397
|
) -> Any:
|
|
387
|
-
context,
|
|
398
|
+
context, parentContext = self._setup_call_func()
|
|
388
399
|
|
|
389
400
|
with self:
|
|
390
401
|
self._init_context(
|
|
391
402
|
context,
|
|
392
|
-
|
|
403
|
+
parentContext,
|
|
393
404
|
proxy,
|
|
394
405
|
limit_ids,
|
|
395
|
-
request_tags,
|
|
396
406
|
experience_name,
|
|
397
407
|
experience_id,
|
|
398
408
|
use_case_name,
|
|
@@ -493,7 +503,7 @@ class _PayiInstrumentor:
|
|
|
493
503
|
|
|
494
504
|
# after _udpate_headers, all metadata to add to ingest is in extra_headers, keyed by the xproxy-xxx header name
|
|
495
505
|
extra_headers = kwargs.get("extra_headers", {})
|
|
496
|
-
self.
|
|
506
|
+
self._update_extra_headers(context, extra_headers)
|
|
497
507
|
|
|
498
508
|
if context.get("proxy", True):
|
|
499
509
|
if "extra_headers" not in kwargs:
|
|
@@ -617,7 +627,7 @@ class _PayiInstrumentor:
|
|
|
617
627
|
|
|
618
628
|
# after _udpate_headers, all metadata to add to ingest is in extra_headers, keyed by the xproxy-xxx header name
|
|
619
629
|
extra_headers = kwargs.get("extra_headers", {})
|
|
620
|
-
self.
|
|
630
|
+
self._update_extra_headers(context, extra_headers)
|
|
621
631
|
|
|
622
632
|
if context.get("proxy", True):
|
|
623
633
|
if "extra_headers" not in kwargs:
|
|
@@ -728,88 +738,74 @@ class _PayiInstrumentor:
|
|
|
728
738
|
return response
|
|
729
739
|
|
|
730
740
|
@staticmethod
|
|
731
|
-
def
|
|
741
|
+
def _update_extra_headers(
|
|
732
742
|
context: _Context,
|
|
733
743
|
extra_headers: "dict[str, str]",
|
|
734
744
|
) -> None:
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
745
|
+
context_limit_ids: Optional[list[str]] = context.get("limit_ids")
|
|
746
|
+
context_experience_name: Optional[str] = context.get("experience_name")
|
|
747
|
+
context_experience_id: Optional[str] = context.get("experience_id")
|
|
748
|
+
context_use_case_name: Optional[str] = context.get("use_case_name")
|
|
749
|
+
context_use_case_id: Optional[str] = context.get("use_case_id")
|
|
750
|
+
context_use_case_version: Optional[int] = context.get("use_case_version")
|
|
751
|
+
context_user_id: Optional[str] = context.get("user_id")
|
|
752
|
+
|
|
753
|
+
# headers_limit_ids = extra_headers.get(PayiHeaderNames.limit_ids, None)
|
|
754
|
+
|
|
755
|
+
# If the caller specifies limit_ids in extra_headers, it takes precedence over the decorator
|
|
756
|
+
if PayiHeaderNames.limit_ids in extra_headers:
|
|
757
|
+
headers_limit_ids = extra_headers.get(PayiHeaderNames.limit_ids)
|
|
758
|
+
|
|
759
|
+
if headers_limit_ids is None or len(headers_limit_ids) == 0:
|
|
760
|
+
# headers_limit_ids is empty, remove it from extra_headers
|
|
761
|
+
extra_headers.pop(PayiHeaderNames.limit_ids, None)
|
|
762
|
+
else:
|
|
763
|
+
# leave the value in extra_headers
|
|
764
|
+
...
|
|
765
|
+
elif context_limit_ids:
|
|
766
|
+
extra_headers[PayiHeaderNames.limit_ids] = ",".join(context_limit_ids)
|
|
767
|
+
|
|
768
|
+
if PayiHeaderNames.user_id in extra_headers:
|
|
769
|
+
headers_user_id = extra_headers.get(PayiHeaderNames.user_id, None)
|
|
770
|
+
if headers_user_id is None or len(headers_user_id) == 0:
|
|
771
|
+
# headers_user_id is empty, remove it from extra_headers
|
|
772
|
+
extra_headers.pop(PayiHeaderNames.user_id, None)
|
|
750
773
|
else:
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
if
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
extra_headers
|
|
774
|
+
# leave the value in extra_headers
|
|
775
|
+
...
|
|
776
|
+
elif context_user_id:
|
|
777
|
+
extra_headers[PayiHeaderNames.user_id] = context_user_id
|
|
778
|
+
|
|
779
|
+
if PayiHeaderNames.use_case_name in extra_headers:
|
|
780
|
+
headers_use_case_name = extra_headers.get(PayiHeaderNames.use_case_name, None)
|
|
781
|
+
if headers_use_case_name is None or len(headers_use_case_name) == 0:
|
|
782
|
+
# headers_use_case_name is empty, remove all use case related headers
|
|
783
|
+
extra_headers.pop(PayiHeaderNames.use_case_name, None)
|
|
784
|
+
extra_headers.pop(PayiHeaderNames.use_case_id, None)
|
|
785
|
+
extra_headers.pop(PayiHeaderNames.use_case_version, None)
|
|
761
786
|
else:
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
extra_headers
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
elif
|
|
781
|
-
|
|
782
|
-
if
|
|
783
|
-
extra_headers[PayiHeaderNames.
|
|
784
|
-
|
|
785
|
-
else:
|
|
786
|
-
# use the inner experience name and id as-is
|
|
787
|
-
...
|
|
788
|
-
|
|
789
|
-
# inner extra_headers use_casee_name and use_case_id take precedence over outer decorator use_case_name and use_case_id
|
|
790
|
-
# if either inner value is specified, ignore outer decorator values
|
|
791
|
-
if PayiHeaderNames.use_case_name not in extra_headers and PayiHeaderNames.use_case_id not in extra_headers:
|
|
792
|
-
|
|
793
|
-
# use decorator values
|
|
794
|
-
if use_case_name is not None:
|
|
795
|
-
extra_headers[PayiHeaderNames.use_case_name] = use_case_name
|
|
796
|
-
if use_case_id is not None:
|
|
797
|
-
extra_headers[PayiHeaderNames.use_case_id] = use_case_id
|
|
798
|
-
if use_case_version is not None:
|
|
799
|
-
extra_headers[PayiHeaderNames.use_case_version] = str(use_case_version)
|
|
800
|
-
|
|
801
|
-
elif PayiHeaderNames.use_case_id in extra_headers and PayiHeaderNames.use_case_name not in extra_headers:
|
|
802
|
-
# use the decorator experience name and the inner experience id
|
|
803
|
-
if use_case_name is not None:
|
|
804
|
-
extra_headers[PayiHeaderNames.use_case_name] = use_case_name
|
|
805
|
-
|
|
806
|
-
# use the decorator experience version and the inner experience id
|
|
807
|
-
if use_case_version is not None:
|
|
808
|
-
extra_headers[PayiHeaderNames.use_case_version] = str(use_case_version) # TODO use case
|
|
809
|
-
|
|
810
|
-
else:
|
|
811
|
-
# use the inner experience name and id as-is
|
|
812
|
-
...
|
|
787
|
+
# leave the value in extra_headers
|
|
788
|
+
...
|
|
789
|
+
elif context_use_case_name:
|
|
790
|
+
extra_headers[PayiHeaderNames.use_case_name] = context_use_case_name
|
|
791
|
+
if context_use_case_id is not None:
|
|
792
|
+
extra_headers[PayiHeaderNames.use_case_id] = context_use_case_id
|
|
793
|
+
if context_use_case_version is not None:
|
|
794
|
+
extra_headers[PayiHeaderNames.use_case_version] = str(context_use_case_version)
|
|
795
|
+
|
|
796
|
+
if PayiHeaderNames.experience_name in extra_headers:
|
|
797
|
+
headers_experience_name = extra_headers.get(PayiHeaderNames.experience_name, None)
|
|
798
|
+
if headers_experience_name is None or len(headers_experience_name) == 0:
|
|
799
|
+
# headers_experience_name is empty, remove all experience related headers
|
|
800
|
+
extra_headers.pop(PayiHeaderNames.experience_name, None)
|
|
801
|
+
extra_headers.pop(PayiHeaderNames.experience_id, None)
|
|
802
|
+
else:
|
|
803
|
+
# leave the value in extra_headers
|
|
804
|
+
...
|
|
805
|
+
elif context_experience_name is not None:
|
|
806
|
+
extra_headers[PayiHeaderNames.experience_name] = context_experience_name
|
|
807
|
+
if context_experience_id is not None:
|
|
808
|
+
extra_headers[PayiHeaderNames.experience_id] = context_experience_id
|
|
813
809
|
|
|
814
810
|
@staticmethod
|
|
815
811
|
def update_for_vision(input: int, units: 'dict[str, Units]') -> int:
|
|
@@ -1020,18 +1016,6 @@ def payi_instrument(
|
|
|
1020
1016
|
elif isinstance(p, AsyncPayi): # type: ignore
|
|
1021
1017
|
apayi_param = p
|
|
1022
1018
|
|
|
1023
|
-
global_context: _Context = {}
|
|
1024
|
-
|
|
1025
|
-
if config and len(config) > 0:
|
|
1026
|
-
if "proxy" not in config:
|
|
1027
|
-
config["proxy"] = False
|
|
1028
|
-
global_context = {**config}
|
|
1029
|
-
|
|
1030
|
-
# create the clients on their behalf if not provided for global ingest instrumentation
|
|
1031
|
-
if not payi_param and not apayi_param and len(global_context) > 0 and global_context.get("proxy", False):
|
|
1032
|
-
payi_param = Payi()
|
|
1033
|
-
apayi_param = AsyncPayi()
|
|
1034
|
-
|
|
1035
1019
|
# allow for both payi and apayi to be None for the @proxy case
|
|
1036
1020
|
_instrumentor = _PayiInstrumentor(
|
|
1037
1021
|
payi=payi_param,
|
|
@@ -1039,19 +1023,11 @@ def payi_instrument(
|
|
|
1039
1023
|
instruments=instruments,
|
|
1040
1024
|
log_prompt_and_response=log_prompt_and_response,
|
|
1041
1025
|
prompt_and_response_logger=prompt_and_response_logger,
|
|
1026
|
+
global_config=config,
|
|
1042
1027
|
)
|
|
1043
1028
|
|
|
1044
|
-
if len(global_context) > 0:
|
|
1045
|
-
if "use_case_name" in global_context and not "use_case_id" in global_context:
|
|
1046
|
-
global_context["use_case_id"] = str(uuid.uuid4())
|
|
1047
|
-
if "experience_name" in global_context and not "experience_id" in global_context:
|
|
1048
|
-
global_context["experience_id"] = str(uuid.uuid4())
|
|
1049
|
-
|
|
1050
|
-
_instrumentor._context_stack.append(global_context)
|
|
1051
|
-
|
|
1052
1029
|
def ingest(
|
|
1053
1030
|
limit_ids: Optional["list[str]"] = None,
|
|
1054
|
-
request_tags: Optional["list[str]"] = None,
|
|
1055
1031
|
experience_name: Optional[str] = None,
|
|
1056
1032
|
experience_id: Optional[str] = None,
|
|
1057
1033
|
use_case_name: Optional[str] = None,
|
|
@@ -1070,7 +1046,6 @@ def ingest(
|
|
|
1070
1046
|
func,
|
|
1071
1047
|
False,
|
|
1072
1048
|
limit_ids,
|
|
1073
|
-
request_tags,
|
|
1074
1049
|
experience_name,
|
|
1075
1050
|
experience_id,
|
|
1076
1051
|
use_case_name,
|
|
@@ -1089,7 +1064,6 @@ def ingest(
|
|
|
1089
1064
|
func,
|
|
1090
1065
|
False,
|
|
1091
1066
|
limit_ids,
|
|
1092
|
-
request_tags,
|
|
1093
1067
|
experience_name,
|
|
1094
1068
|
experience_id,
|
|
1095
1069
|
use_case_name,
|
|
@@ -1104,7 +1078,6 @@ def ingest(
|
|
|
1104
1078
|
|
|
1105
1079
|
def proxy(
|
|
1106
1080
|
limit_ids: Optional["list[str]"] = None,
|
|
1107
|
-
request_tags: Optional["list[str]"] = None,
|
|
1108
1081
|
experience_name: Optional[str] = None,
|
|
1109
1082
|
experience_id: Optional[str] = None,
|
|
1110
1083
|
use_case_id: Optional[str] = None,
|
|
@@ -1122,7 +1095,6 @@ def proxy(
|
|
|
1122
1095
|
func,
|
|
1123
1096
|
True,
|
|
1124
1097
|
limit_ids,
|
|
1125
|
-
request_tags,
|
|
1126
1098
|
experience_name,
|
|
1127
1099
|
experience_id,
|
|
1128
1100
|
use_case_name,
|
|
@@ -1142,7 +1114,6 @@ def proxy(
|
|
|
1142
1114
|
func,
|
|
1143
1115
|
True,
|
|
1144
1116
|
limit_ids,
|
|
1145
|
-
request_tags,
|
|
1146
1117
|
experience_name,
|
|
1147
1118
|
experience_id,
|
|
1148
1119
|
use_case_name,
|
|
@@ -11,7 +11,7 @@ payi/_resource.py,sha256=j2jIkTr8OIC8sU6-05nxSaCyj4MaFlbZrwlyg4_xJos,1088
|
|
|
11
11
|
payi/_response.py,sha256=CfrNS_3wbL8o9dRyRVfZQ5E1GUlA4CUIUEK8olmfGqE,28777
|
|
12
12
|
payi/_streaming.py,sha256=Z_wIyo206T6Jqh2rolFg2VXZgX24PahLmpURp0-NssU,10092
|
|
13
13
|
payi/_types.py,sha256=2mbMK86K3W1aMTW7sOGQ-VND6-A2IuXKm8p4sYFztBU,6141
|
|
14
|
-
payi/_version.py,sha256=
|
|
14
|
+
payi/_version.py,sha256=NwcYowxE17eI_XA6hOCHPtbfRQYksPdV6qi3Qzr03Zg,165
|
|
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=PNZ_QJuzZEgyYXqkO1HVhGkj5IU9bglVUcw7H-Knjzw,2062
|
|
@@ -20,7 +20,7 @@ payi/_utils/_proxy.py,sha256=z3zsateHtb0EARTWKk8QZNHfPkqJbqwd1lM993LBwGE,1902
|
|
|
20
20
|
payi/_utils/_reflection.py,sha256=ZmGkIgT_PuwedyNBrrKGbxoWtkpytJNU1uU4QHnmEMU,1364
|
|
21
21
|
payi/_utils/_streams.py,sha256=SMC90diFFecpEg_zgDRVbdR3hSEIgVVij4taD-noMLM,289
|
|
22
22
|
payi/_utils/_sync.py,sha256=TpGLrrhRNWTJtODNE6Fup3_k7zrWm1j2RlirzBwre-0,2862
|
|
23
|
-
payi/_utils/_transform.py,sha256=
|
|
23
|
+
payi/_utils/_transform.py,sha256=xfcRTFidCyPhQ7hXeivxpAS0x-NhTyr20iXm1cKcJYk,14857
|
|
24
24
|
payi/_utils/_typing.py,sha256=nTJz0jcrQbEgxwy4TtAkNxuU0QHHlmc6mQtA6vIR8tg,4501
|
|
25
25
|
payi/_utils/_utils.py,sha256=8UmbPOy_AAr2uUjjFui-VZSrVBHRj6bfNEKRp5YZP2A,12004
|
|
26
26
|
payi/lib/.keep,sha256=wuNrz-5SXo3jJaJOJgz4vFHM41YH_g20F5cRQo0vLes,224
|
|
@@ -28,8 +28,8 @@ payi/lib/AnthropicInstrumentor.py,sha256=mqSkULumXbGQ9N2Q6Qf5f0IHo0E0Ss9wPWxXaTl
|
|
|
28
28
|
payi/lib/BedrockInstrumentor.py,sha256=UGJiPSjYEuVWLLQu4kUMVrZfx6YJhC3IX4JNoOdcJQ8,10088
|
|
29
29
|
payi/lib/OpenAIInstrumentor.py,sha256=Zdjaj1l2vteujPp3Bt7zwwbveUEQx6CglB1QIniVzL8,6898
|
|
30
30
|
payi/lib/Stopwatch.py,sha256=7OJlxvr2Jyb6Zr1LYCYKczRB7rDVKkIR7gc4YoleNdE,764
|
|
31
|
-
payi/lib/helpers.py,sha256=
|
|
32
|
-
payi/lib/instrument.py,sha256=
|
|
31
|
+
payi/lib/helpers.py,sha256=dEscgoiCneUx1rbgayt8P-s-xi0gKiN2vWiKYMS7oiQ,3830
|
|
32
|
+
payi/lib/instrument.py,sha256=k8Vb0Y6Qe8UVEPcXnNJn4Ovw08fpaO1XduI77tkEslo,43182
|
|
33
33
|
payi/resources/__init__.py,sha256=1rtrPLWbNt8oJGOp6nwPumKLJ-ftez0B6qwLFyfcoP4,2972
|
|
34
34
|
payi/resources/ingest.py,sha256=ifKMKylIkfCF-uGFPttr_VG3vWxsqntOOBrrU4_g1zk,21627
|
|
35
35
|
payi/resources/categories/__init__.py,sha256=w5gMiPdBSzJA_qfoVtFBElaoe8wGf_O63R7R1Spr6Gk,1093
|
|
@@ -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=pzQza_16N3z8cFNEKr6gPbFvuGFrwNuGxAYb--Kbo2M,449
|
|
138
|
-
payi-0.1.
|
|
139
|
-
payi-0.1.
|
|
140
|
-
payi-0.1.
|
|
141
|
-
payi-0.1.
|
|
138
|
+
payi-0.1.0a64.dist-info/METADATA,sha256=_O20WUNp7iEAAIvh7f_e0ULa7_JqhM73sx5XlGpcjT8,15290
|
|
139
|
+
payi-0.1.0a64.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
140
|
+
payi-0.1.0a64.dist-info/licenses/LICENSE,sha256=CQt03aM-P4a3Yg5qBg3JSLVoQS3smMyvx7tYg_6V7Gk,11334
|
|
141
|
+
payi-0.1.0a64.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|