payi 0.1.0a78__py3-none-any.whl → 0.1.0a80__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.78" # x-release-please-version
4
+ __version__ = "0.1.0-alpha.80" # x-release-please-version
@@ -190,16 +190,20 @@ class _AnthropicProviderRequest(_ProviderRequest):
190
190
  estimated_token_count = 0
191
191
  has_image = False
192
192
 
193
- enc = tiktoken.get_encoding("cl100k_base")
194
-
195
- for message in messages:
196
- msg_has_image, msg_prompt_tokens = has_image_and_get_texts(enc, message.get('content', ''))
197
- if msg_has_image:
198
- has_image = True
199
- estimated_token_count += msg_prompt_tokens
200
-
201
- if has_image and estimated_token_count > 0:
202
- self._estimated_prompt_tokens = estimated_token_count
193
+ try:
194
+ enc = tiktoken.get_encoding("cl100k_base")
195
+ for message in messages:
196
+ msg_has_image, msg_prompt_tokens = has_image_and_get_texts(enc, message.get('content', ''))
197
+ if msg_has_image:
198
+ has_image = True
199
+ estimated_token_count += msg_prompt_tokens
200
+
201
+ if has_image and estimated_token_count > 0:
202
+ self._estimated_prompt_tokens = estimated_token_count
203
+
204
+ except Exception:
205
+ logging.warning("Error getting encoding for cl100k_base")
206
+
203
207
  return True
204
208
 
205
209
  @override
@@ -279,8 +279,13 @@ class _GoogleGenAiRequest(_ProviderRequest):
279
279
  kwargs: Any) -> Any:
280
280
  response_dict = response.to_json_dict()
281
281
 
282
- self._ingest["provider_response_id"] = response_dict["response_id"]
283
- self._ingest["resource"] = "google." + response_dict["model_version"]
282
+ id: Optional[str] = response_dict.get("response_id", None)
283
+ if id:
284
+ self._ingest["provider_response_id"] = id
285
+
286
+ model: Optional[str] = response_dict.get("model_version", None)
287
+ if model:
288
+ self._ingest["resource"] = "google." + model
284
289
 
285
290
  self._compute_usage(response_dict)
286
291
 
@@ -364,20 +364,26 @@ class _OpenAiChatProviderRequest(_OpenAiProviderRequest):
364
364
  if messages:
365
365
  estimated_token_count = 0
366
366
  has_image = False
367
+ enc: Optional[tiktoken.Encoding] = None
367
368
 
368
369
  try:
369
370
  enc = tiktoken.encoding_for_model(kwargs.get("model")) # type: ignore
370
- except KeyError:
371
- enc = tiktoken.get_encoding("o200k_base") # type: ignore
371
+ except Exception:
372
+ try:
373
+ enc = tiktoken.get_encoding("o200k_base") # type: ignore
374
+ except Exception:
375
+ logging.warning("Error getting encoding for fallback o200k_base")
376
+ enc = None
372
377
 
373
- for message in messages:
374
- msg_has_image, msg_prompt_tokens = self.has_image_and_get_texts(enc, message.get('content', ''))
375
- if msg_has_image:
376
- has_image = True
377
- estimated_token_count += msg_prompt_tokens
378
+ if enc:
379
+ for message in messages:
380
+ msg_has_image, msg_prompt_tokens = self.has_image_and_get_texts(enc, message.get('content', ''))
381
+ if msg_has_image:
382
+ has_image = True
383
+ estimated_token_count += msg_prompt_tokens
378
384
 
379
- if has_image and estimated_token_count > 0:
380
- self._estimated_prompt_tokens = estimated_token_count
385
+ if has_image and estimated_token_count > 0:
386
+ self._estimated_prompt_tokens = estimated_token_count
381
387
 
382
388
  stream: bool = kwargs.get("stream", False)
383
389
  if stream:
@@ -436,11 +442,16 @@ class _OpenAiResponsesProviderRequest(_OpenAiProviderRequest):
436
442
 
437
443
  estimated_token_count = 0
438
444
  has_image = False
445
+ enc: Optional[tiktoken.Encoding] = None
439
446
 
440
447
  try:
441
448
  enc = tiktoken.encoding_for_model(kwargs.get("model")) # type: ignore
442
- except KeyError:
443
- enc = tiktoken.get_encoding("o200k_base") # type: ignore
449
+ except Exception:
450
+ try:
451
+ enc = tiktoken.get_encoding("o200k_base") # type: ignore
452
+ except Exception:
453
+ logging.warning("Error getting encoding for fallback o200k_base")
454
+ enc = None
444
455
 
445
456
  # find each content..type="input_text" and count tokens
446
457
  # input=[{
@@ -456,18 +467,19 @@ class _OpenAiResponsesProviderRequest(_OpenAiProviderRequest):
456
467
  # },
457
468
  # ],
458
469
  # }]
459
- for item in input: # type: ignore
460
- if isinstance(item, dict):
461
- for key, value in item.items(): # type: ignore
462
- if key == "content":
463
- if isinstance(value, list):
464
- msg_has_image, msg_prompt_tokens = self.has_image_and_get_texts(enc, value, image_type="input_image", text_type="input_text") # type: ignore
465
- if msg_has_image:
466
- has_image = True
467
- estimated_token_count += msg_prompt_tokens
468
-
469
- if has_image and estimated_token_count > 0:
470
- self._estimated_prompt_tokens = estimated_token_count
470
+ if enc:
471
+ for item in input: # type: ignore
472
+ if isinstance(item, dict):
473
+ for key, value in item.items(): # type: ignore
474
+ if key == "content":
475
+ if isinstance(value, list):
476
+ msg_has_image, msg_prompt_tokens = self.has_image_and_get_texts(enc, value, image_type="input_image", text_type="input_text") # type: ignore
477
+ if msg_has_image:
478
+ has_image = True
479
+ estimated_token_count += msg_prompt_tokens
480
+
481
+ if has_image and estimated_token_count > 0:
482
+ self._estimated_prompt_tokens = estimated_token_count
471
483
 
472
484
  return True
473
485
 
@@ -225,8 +225,13 @@ class _GoogleVertexRequest(_ProviderRequest):
225
225
  kwargs: Any) -> Any:
226
226
  response_dict = response.to_dict()
227
227
 
228
- self._ingest["provider_response_id"] = response_dict["response_id"]
229
- self._ingest["resource"] = "google." + response_dict["model_version"]
228
+ id: Optional[str] = response_dict.get("response_id", None)
229
+ if id:
230
+ self._ingest["provider_response_id"] = id
231
+
232
+ model: Optional[str] = response_dict.get("model_version", None)
233
+ if model:
234
+ self._ingest["resource"] = "google." + model
230
235
 
231
236
  self._compute_usage(response_dict)
232
237
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: payi
3
- Version: 0.1.0a78
3
+ Version: 0.1.0a80
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=562XNlpNWouu5fR8P9024ptW4UWs2S750PSKhFzqfdY,165
14
+ payi/_version.py,sha256=8owWzJCmVOUMtN_Md7Vwk-OBmbGW5fhSMc2EUWFK3X8,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
@@ -25,12 +25,12 @@ payi/_utils/_transform.py,sha256=n7kskEWz6o__aoNvhFoGVyDoalNe6mJwp-g7BWkdj88,156
25
25
  payi/_utils/_typing.py,sha256=D0DbbNu8GnYQTSICnTSHDGsYXj8TcAKyhejb0XcnjtY,4602
26
26
  payi/_utils/_utils.py,sha256=ts4CiiuNpFiGB6YMdkQRh2SZvYvsl7mAF-JWHCcLDf4,12312
27
27
  payi/lib/.keep,sha256=wuNrz-5SXo3jJaJOJgz4vFHM41YH_g20F5cRQo0vLes,224
28
- payi/lib/AnthropicInstrumentor.py,sha256=q1Iq2NG06OHUwcwTgYjHa1_kwhbSxE3vrGk_fm5IGSM,8749
28
+ payi/lib/AnthropicInstrumentor.py,sha256=Y7W99dwnaAM4W5IIkmeGLaTunoMsBDt-AjUasrI1mXM,8900
29
29
  payi/lib/BedrockInstrumentor.py,sha256=cIjHlPQmVEAixabUoT3mV8h50lfzdc1u8iLj0gQNukE,14076
30
- payi/lib/GoogleGenAiInstrumentor.py,sha256=y9FuEtuITaIac_N-WhmypAr-UF1lzRCc9YBRVwwwydQ,13411
31
- payi/lib/OpenAIInstrumentor.py,sha256=iMOriAm-2zcRNjQDkEAG-NfZhBJUnkBDrNNbO920ajc,17468
30
+ payi/lib/GoogleGenAiInstrumentor.py,sha256=isfuYH0y9LZZPcjPkynRQzwhtsN9H2p4DqtPYTm8hqI,13549
31
+ payi/lib/OpenAIInstrumentor.py,sha256=6h5MYtj4jAXEJZ_IyMriZxWXrN-hQ7SdJXIQW7DrTFo,18014
32
32
  payi/lib/Stopwatch.py,sha256=7OJlxvr2Jyb6Zr1LYCYKczRB7rDVKkIR7gc4YoleNdE,764
33
- payi/lib/VertexInstrumentor.py,sha256=Xmp5kRI8G0u2OieGmlNxIduwnqp8cAXO-fROpkdXbgs,11748
33
+ payi/lib/VertexInstrumentor.py,sha256=aW4ZT7YVXy8V_g91KkSEapzI7Cy6UQfaU1D0ZOU4eBE,11886
34
34
  payi/lib/helpers.py,sha256=K1KAfWrpPT1UUGNxspLe1lHzQjP3XV5Pkh9IU4pKMok,4624
35
35
  payi/lib/instrument.py,sha256=UpZ6SGg3YI9lSxmwH5ziwe1xt_ca6FS35CcNJpG9ONM,58214
36
36
  payi/resources/__init__.py,sha256=1rtrPLWbNt8oJGOp6nwPumKLJ-ftez0B6qwLFyfcoP4,2972
@@ -142,7 +142,7 @@ payi/types/use_cases/definitions/kpi_retrieve_response.py,sha256=uQXliSvS3k-yDYw
142
142
  payi/types/use_cases/definitions/kpi_update_params.py,sha256=jbawdWAdMnsTWVH0qfQGb8W7_TXe3lq4zjSRu44d8p8,373
143
143
  payi/types/use_cases/definitions/kpi_update_response.py,sha256=zLyEoT0S8d7XHsnXZYT8tM7yDw0Aze0Mk-_Z6QeMtc8,459
144
144
  payi/types/use_cases/definitions/limit_config_create_params.py,sha256=pzQza_16N3z8cFNEKr6gPbFvuGFrwNuGxAYb--Kbo2M,449
145
- payi-0.1.0a78.dist-info/METADATA,sha256=kKY9frrRc7_WbcIUIphMDmRBHQVZgdSGH1eLkF26Pzk,15180
146
- payi-0.1.0a78.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
147
- payi-0.1.0a78.dist-info/licenses/LICENSE,sha256=CQt03aM-P4a3Yg5qBg3JSLVoQS3smMyvx7tYg_6V7Gk,11334
148
- payi-0.1.0a78.dist-info/RECORD,,
145
+ payi-0.1.0a80.dist-info/METADATA,sha256=__22ITl_q65jasQ663-ur0WOvHXW-PYzIVu0tq6PnYs,15180
146
+ payi-0.1.0a80.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
147
+ payi-0.1.0a80.dist-info/licenses/LICENSE,sha256=CQt03aM-P4a3Yg5qBg3JSLVoQS3smMyvx7tYg_6V7Gk,11334
148
+ payi-0.1.0a80.dist-info/RECORD,,