payi 0.1.0a92__py3-none-any.whl → 0.1.0a93__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/_version.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
3
  __title__ = "payi"
4
- __version__ = "0.1.0-alpha.92" # x-release-please-version
4
+ __version__ = "0.1.0-alpha.93" # x-release-please-version
@@ -88,7 +88,6 @@ class _GoogleVertexRequest(_VertexRequest):
88
88
  )
89
89
  self._prompt_character_count = 0
90
90
  self._candidates_character_count = 0
91
- self._model_name: Optional[str] = None
92
91
 
93
92
  @override
94
93
  def process_request(self, instance: Any, extra_headers: 'dict[str, str]', args: Sequence[Any], kwargs: Any) -> bool:
@@ -100,7 +99,7 @@ class _GoogleVertexRequest(_VertexRequest):
100
99
  if model and isinstance(model, str):
101
100
  # Extract the model name after the last slash
102
101
  self._model_name = model.split('/')[-1]
103
-
102
+
104
103
  if not args:
105
104
  return True
106
105
 
payi/lib/instrument.py CHANGED
@@ -1,5 +1,6 @@
1
1
  import os
2
2
  import json
3
+ import time
3
4
  import uuid
4
5
  import asyncio
5
6
  import inspect
@@ -14,7 +15,7 @@ from dataclasses import dataclass
14
15
  import nest_asyncio # type: ignore
15
16
  from wrapt import ObjectProxy # type: ignore
16
17
 
17
- from payi import Payi, AsyncPayi, __version__ as _payi_version
18
+ from payi import Payi, AsyncPayi, APIConnectionError, __version__ as _payi_version
18
19
  from payi.types import IngestUnitsParams
19
20
  from payi.lib.helpers import PayiHeaderNames
20
21
  from payi.types.ingest_response import IngestResponse
@@ -137,6 +138,7 @@ class PayiInstrumentConfig(TypedDict, total=False):
137
138
  proxy: bool
138
139
  global_instrumentation: bool
139
140
  instrument_inline_data: bool
141
+ connection_error_logging_window: int
140
142
  limit_ids: Optional["list[str]"]
141
143
  use_case_name: Optional[str]
142
144
  use_case_id: Optional[str]
@@ -222,6 +224,12 @@ class _PayiInstrumentor:
222
224
  self._blocked_limits: set[str] = set()
223
225
  self._exceeded_limits: set[str] = set()
224
226
 
227
+ self._api_connection_error_last_log_time: float = time.time()
228
+ self._api_connection_error_count: int = 0
229
+ self._api_connection_error_window: int = global_config.get("connection_error_logging_window", 60)
230
+ if self._api_connection_error_window < 0:
231
+ raise ValueError("connection_error_logging_window must be a non-negative integer")
232
+
225
233
  # default is instrument and ingest metrics
226
234
  self._proxy_default: bool = global_config.get("proxy", False)
227
235
 
@@ -353,6 +361,9 @@ class _PayiInstrumentor:
353
361
  # convert the function call builder to a list of function calls
354
362
  ingest_units["provider_response_function_calls"] = list(request._function_call_builder.values())
355
363
 
364
+ if 'resource' not in ingest_units or len(ingest_units['resource']) == 0:
365
+ ingest_units['resource'] = "system.unknown_model" # type: ignore[unreachable]
366
+
356
367
  request_json = ingest_units.get('provider_request_json', "")
357
368
  if request_json and self._instrument_inline_data is False:
358
369
  try:
@@ -402,6 +413,23 @@ class _PayiInstrumentor:
402
413
  if removeBlockedId:
403
414
  self._blocked_limits.discard(limit_id)
404
415
 
416
+ def _process_ingest_connection_error(self, e: APIConnectionError, ingest_units: IngestUnitsParams) -> None:
417
+ now = time.time()
418
+
419
+ if (now - self._api_connection_error_last_log_time) > self._api_connection_error_window:
420
+ # If previous window had suppressed errors, log the count
421
+ append = ""
422
+ if self._api_connection_error_count > 0:
423
+ append = f", {self._api_connection_error_count} APIConnectionError exceptions in the last {self._api_connection_error_window} seconds"
424
+
425
+ # Log the current error
426
+ self._logger.error(f"Error Pay-i ingesting: connection exception {e}, request {ingest_units}{append}")
427
+ self._api_connection_error_last_log_time = now
428
+ self._api_connection_error_count = 0
429
+ else:
430
+ # Suppress and count
431
+ self._api_connection_error_count += 1
432
+
405
433
  async def _aingest_units(self, request: _ProviderRequest) -> Optional[IngestResponse]:
406
434
  ingest_response: Optional[IngestResponse] = None
407
435
  ingest_units = request._ingest
@@ -437,7 +465,10 @@ class _PayiInstrumentor:
437
465
 
438
466
  return ingest_response
439
467
  except Exception as e:
440
- self._logger.error(f"Error Pay-i async ingesting: exception {e}, request {ingest_units}")
468
+ if isinstance(e, APIConnectionError) and self._api_connection_error_window > 0:
469
+ self._process_ingest_connection_error(e, ingest_units)
470
+ else:
471
+ self._logger.error(f"Error Pay-i async ingesting: exception {e}, request {ingest_units}")
441
472
 
442
473
  return None
443
474
 
@@ -513,7 +544,10 @@ class _PayiInstrumentor:
513
544
  self._logger.error("No payi instance to ingest units")
514
545
 
515
546
  except Exception as e:
516
- self._logger.error(f"Error Pay-i ingesting: exception {e}, request {ingest_units}")
547
+ if isinstance(e, APIConnectionError) and self._api_connection_error_window > 0:
548
+ self._process_ingest_connection_error(e, ingest_units)
549
+ else:
550
+ self._logger.error(f"Error Pay-i ingesting: exception {e}, request {ingest_units}")
517
551
 
518
552
  return None
519
553
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: payi
3
- Version: 0.1.0a92
3
+ Version: 0.1.0a93
4
4
  Summary: The official Python library for the payi API
5
5
  Project-URL: Homepage, https://github.com/Pay-i/pay-i-python
6
6
  Project-URL: Repository, https://github.com/Pay-i/pay-i-python
@@ -11,7 +11,7 @@ payi/_resource.py,sha256=j2jIkTr8OIC8sU6-05nxSaCyj4MaFlbZrwlyg4_xJos,1088
11
11
  payi/_response.py,sha256=rh9oJAvCKcPwQFm4iqH_iVrmK8bNx--YP_A2a4kN1OU,28776
12
12
  payi/_streaming.py,sha256=Z_wIyo206T6Jqh2rolFg2VXZgX24PahLmpURp0-NssU,10092
13
13
  payi/_types.py,sha256=7jE5MoQQFVoVxw5vVzvZ2Ao0kcjfNOGsBgyJfLBEnMo,6195
14
- payi/_version.py,sha256=enwqQZXbXCLnYJiMH-ERIVZQXanTzI_DXQADR3N5aK4,165
14
+ payi/_version.py,sha256=F--xck4QJ1Rqyg7T3nA-GXHI12z2X-gLM-k7V8Bawok,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
@@ -30,10 +30,10 @@ payi/lib/BedrockInstrumentor.py,sha256=Vx0DUjdYzHWAuYsmK28z9Bxz-mj7UouEESsCN3B9J
30
30
  payi/lib/GoogleGenAiInstrumentor.py,sha256=DLbmlwmyOwooe7FuBkEAO_Z3xjPKpvQyO4VwLBeZnn4,8477
31
31
  payi/lib/OpenAIInstrumentor.py,sha256=6HENrdN6kLMUwC00wNSdeGeK4fUDBWo2dCbVC9koi0c,22581
32
32
  payi/lib/Stopwatch.py,sha256=7OJlxvr2Jyb6Zr1LYCYKczRB7rDVKkIR7gc4YoleNdE,764
33
- payi/lib/VertexInstrumentor.py,sha256=IdahkOgB6ReBGpdgGCrBHplAFwK3KZ_XaRgFXVTodRU,7136
33
+ payi/lib/VertexInstrumentor.py,sha256=q-oYr3YuwPc95xYn6KhjvKs5ZweGRg6mOIkxSTz-lic,7081
34
34
  payi/lib/VertexRequest.py,sha256=NNH6S86nCHaU54Rb1rxai-b3UiJvatmzKkDKBmqMeKY,10530
35
35
  payi/lib/helpers.py,sha256=FPzNSSHGf9bgD6CanB7yVx_U8t4lm2c0jlZKrsziYlc,4242
36
- payi/lib/instrument.py,sha256=CiUtYwpTeoFbm7EEBXSbfaE5ZJKNuu7-ZfrXMi3hINM,62954
36
+ payi/lib/instrument.py,sha256=oVN1KL2CqKcdcloDnWi7OQOXtq5df4bx6UHTYfBSnZs,64834
37
37
  payi/resources/__init__.py,sha256=1rtrPLWbNt8oJGOp6nwPumKLJ-ftez0B6qwLFyfcoP4,2972
38
38
  payi/resources/ingest.py,sha256=Z4WHv-INZoIlBzFw4o1j_PHykDsNACpkkF42Kik0UMg,23758
39
39
  payi/resources/categories/__init__.py,sha256=WeotN_d-0Ri8ohsrNPbve7RyViD9_N0NA9DrV3WYg3w,1701
@@ -145,7 +145,7 @@ payi/types/use_cases/definitions/kpi_retrieve_response.py,sha256=uQXliSvS3k-yDYw
145
145
  payi/types/use_cases/definitions/kpi_update_params.py,sha256=jbawdWAdMnsTWVH0qfQGb8W7_TXe3lq4zjSRu44d8p8,373
146
146
  payi/types/use_cases/definitions/kpi_update_response.py,sha256=zLyEoT0S8d7XHsnXZYT8tM7yDw0Aze0Mk-_Z6QeMtc8,459
147
147
  payi/types/use_cases/definitions/limit_config_create_params.py,sha256=pzQza_16N3z8cFNEKr6gPbFvuGFrwNuGxAYb--Kbo2M,449
148
- payi-0.1.0a92.dist-info/METADATA,sha256=KpNUrDFlrf_yCeznM4MLB7tVMSkU8t5mjdHvG73pd3o,16333
149
- payi-0.1.0a92.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
150
- payi-0.1.0a92.dist-info/licenses/LICENSE,sha256=CQt03aM-P4a3Yg5qBg3JSLVoQS3smMyvx7tYg_6V7Gk,11334
151
- payi-0.1.0a92.dist-info/RECORD,,
148
+ payi-0.1.0a93.dist-info/METADATA,sha256=qqHi5iuUQKASaIN0sVyCrW6CT9flyqMiO_f3TH1MNFQ,16333
149
+ payi-0.1.0a93.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
150
+ payi-0.1.0a93.dist-info/licenses/LICENSE,sha256=CQt03aM-P4a3Yg5qBg3JSLVoQS3smMyvx7tYg_6V7Gk,11334
151
+ payi-0.1.0a93.dist-info/RECORD,,