payi 0.1.0a125__py3-none-any.whl → 0.1.0a127__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.

Files changed (31) hide show
  1. payi/_version.py +1 -1
  2. payi/lib/BedrockInstrumentor.py +35 -25
  3. payi/lib/helpers.py +12 -0
  4. payi/lib/instrument.py +136 -143
  5. payi/resources/categories/__init__.py +0 -14
  6. payi/resources/categories/categories.py +0 -32
  7. payi/resources/categories/resources.py +4 -0
  8. payi/resources/ingest.py +20 -8
  9. payi/resources/requests/request_id/properties.py +3 -3
  10. payi/resources/requests/response_id/properties.py +3 -3
  11. payi/resources/use_cases/properties.py +3 -3
  12. payi/types/__init__.py +2 -0
  13. payi/types/bulk_ingest_response.py +3 -20
  14. payi/types/categories/__init__.py +0 -1
  15. payi/types/categories/resource_list_params.py +5 -1
  16. payi/types/category_resource_response.py +31 -1
  17. payi/types/ingest_event_param.py +2 -2
  18. payi/types/ingest_units_params.py +2 -2
  19. payi/types/requests/request_id/property_update_params.py +2 -2
  20. payi/types/requests/response_id/property_update_params.py +2 -2
  21. payi/types/shared/__init__.py +2 -0
  22. payi/types/shared/api_error.py +18 -0
  23. payi/types/shared/properties_request.py +11 -0
  24. payi/types/shared/xproxy_result.py +2 -0
  25. payi/types/use_cases/property_update_params.py +2 -2
  26. {payi-0.1.0a125.dist-info → payi-0.1.0a127.dist-info}/METADATA +1 -1
  27. {payi-0.1.0a125.dist-info → payi-0.1.0a127.dist-info}/RECORD +29 -29
  28. payi/resources/categories/fixed_cost_resources.py +0 -196
  29. payi/types/categories/fixed_cost_resource_create_params.py +0 -22
  30. {payi-0.1.0a125.dist-info → payi-0.1.0a127.dist-info}/WHEEL +0 -0
  31. {payi-0.1.0a125.dist-info → payi-0.1.0a127.dist-info}/licenses/LICENSE +0 -0
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.125" # x-release-please-version
4
+ __version__ = "0.1.0-alpha.127" # x-release-please-version
@@ -1,13 +1,12 @@
1
1
  import os
2
2
  import json
3
- from typing import Any, Optional, Sequence
3
+ from typing import TYPE_CHECKING, Any, Optional, Sequence
4
4
  from functools import wraps
5
5
  from typing_extensions import override
6
6
 
7
7
  from wrapt import ObjectProxy, wrap_function_wrapper # type: ignore
8
- from tokenizers import Tokenizer # type: ignore
9
8
 
10
- from payi.lib.helpers import PayiCategories, PayiHeaderNames, payi_aws_bedrock_url
9
+ from payi.lib.helpers import PayiCategories, PayiHeaderNames, PayiPropertyNames, payi_aws_bedrock_url
11
10
  from payi.types.ingest_units_params import Units
12
11
  from payi.types.pay_i_common_models_api_router_header_info_param import PayICommonModelsAPIRouterHeaderInfoParam
13
12
 
@@ -21,9 +20,10 @@ from .instrument import (
21
20
  )
22
21
  from .version_helper import get_version_helper
23
22
 
24
- GUARDRAIL_ID = "system.aws.bedrock.guardrail.id"
25
- GUARDRAIL_VERSION = "system.aws.bedrock.guardrail.version"
26
- GUARDRAIL_ACTION = "system.aws.bedrock.guardrail.action"
23
+ if TYPE_CHECKING:
24
+ from tokenizers import Tokenizer # type: ignore
25
+ else:
26
+ Tokenizer = None
27
27
 
28
28
  GUARDRAIL_SEMANTIC_FAILURE_DESCRIPTION = "Bedrock Guardrails intervened"
29
29
 
@@ -118,9 +118,8 @@ def _redirect_to_payi(request: Any, event_name: str, **_: 'dict[str, Any]') -> N
118
118
  for key, value in extra_headers.items():
119
119
  request.headers[key] = value
120
120
 
121
-
122
121
  class InvokeResponseWrapper(ObjectProxy): # type: ignore
123
- _cohere_embed_english_v3_tokenizer: Optional[Tokenizer] = None
122
+ _cohere_embed_english_v3_tokenizer: Optional['Tokenizer'] = None
124
123
 
125
124
  def __init__(
126
125
  self,
@@ -189,15 +188,26 @@ class InvokeResponseWrapper(ObjectProxy): # type: ignore
189
188
  if texts and len(texts) > 0:
190
189
  text = " ".join(texts)
191
190
 
192
- if self._cohere_embed_english_v3_tokenizer is None:
193
- current_dir = os.path.dirname(os.path.abspath(__file__))
194
- tokenizer_path = os.path.join(current_dir, "data", "cohere_embed_english_v3.json")
195
- self._cohere_embed_english_v3_tokenizer = Tokenizer.from_file(tokenizer_path) # type: ignore
191
+ try:
192
+ from tokenizers import Tokenizer # type: ignore
193
+
194
+ if self._cohere_embed_english_v3_tokenizer is None: # type: ignore
195
+ current_dir = os.path.dirname(os.path.abspath(__file__))
196
+ tokenizer_path = os.path.join(current_dir, "data", "cohere_embed_english_v3.json")
197
+ self._cohere_embed_english_v3_tokenizer = Tokenizer.from_file(tokenizer_path) # type: ignore
198
+
199
+ if self._cohere_embed_english_v3_tokenizer is not None and isinstance(self._cohere_embed_english_v3_tokenizer, Tokenizer): # type: ignore
200
+ tokens: list = self._cohere_embed_english_v3_tokenizer.encode(text, add_special_tokens=False).tokens # type: ignore
196
201
 
197
- tokens: list = self._cohere_embed_english_v3_tokenizer.encode(text, add_special_tokens=False).tokens # type: ignore
202
+ if tokens and isinstance(tokens, list):
203
+ units["text"] = Units(input=len(tokens), output=0) # type: ignore
198
204
 
199
- if tokens and isinstance(tokens, list):
200
- units["text"] = Units(input=len(tokens), output=0) # type: ignore
205
+ except ImportError:
206
+ self._request._instrumentor._logger.warning("tokenizers module not found, caller must install the tokenizers module. Cannot record text tokens for Cohere embed english v3")
207
+ pass
208
+ except Exception as e:
209
+ self._request._instrumentor._logger.warning(f"Error processing Cohere embed english v3 response: {e}")
210
+ pass
201
211
 
202
212
  if self._log_prompt_and_response:
203
213
  ingest["provider_response_json"] = data.decode('utf-8') # type: ignore
@@ -388,11 +398,11 @@ class _BedrockInvokeProviderRequest(_BedrockProviderRequest):
388
398
 
389
399
  guardrail_id = kwargs.get("guardrailIdentifier", "")
390
400
  if guardrail_id:
391
- self.add_internal_request_property(GUARDRAIL_ID, guardrail_id)
401
+ self.add_internal_request_property(PayiPropertyNames.aws_bedrock_guardrail_id, guardrail_id)
392
402
 
393
403
  guardrail_version = kwargs.get("guardrailVersion", "")
394
404
  if guardrail_version:
395
- self.add_internal_request_property(GUARDRAIL_VERSION, guardrail_version)
405
+ self.add_internal_request_property(PayiPropertyNames.aws_bedrock_guardrail_version, guardrail_version)
396
406
 
397
407
  if guardrail_id and guardrail_version and BedrockInstrumentor._guardrail_trace:
398
408
  trace = kwargs.get("trace", None)
@@ -488,9 +498,9 @@ class _BedrockInvokeProviderRequest(_BedrockProviderRequest):
488
498
  def process_stop_action(self, action: str) -> None:
489
499
  # record both as a semantic failure and guardrail action so it is discoverable through both properties
490
500
  if action == "INTERVENED":
491
- self.add_internal_request_property('system.failure', action)
492
- self.add_internal_request_property('system.failure.description', GUARDRAIL_SEMANTIC_FAILURE_DESCRIPTION)
493
- self.add_internal_request_property(GUARDRAIL_ACTION, action)
501
+ self.add_internal_request_property(PayiPropertyNames.failure, action)
502
+ self.add_internal_request_property(PayiPropertyNames.failure_description, GUARDRAIL_SEMANTIC_FAILURE_DESCRIPTION)
503
+ self.add_internal_request_property(PayiPropertyNames.aws_bedrock_guardrail_action, action)
494
504
 
495
505
  @override
496
506
  def remove_inline_data(self, prompt: 'dict[str, Any]') -> bool:# noqa: ARG002
@@ -519,11 +529,11 @@ class _BedrockConverseProviderRequest(_BedrockProviderRequest):
519
529
  if guardrail_config:
520
530
  guardrailIdentifier = guardrail_config.get("guardrailIdentifier", "")
521
531
  if guardrailIdentifier:
522
- self.add_internal_request_property(GUARDRAIL_ID, guardrailIdentifier)
532
+ self.add_internal_request_property(PayiPropertyNames.aws_bedrock_guardrail_id, guardrailIdentifier)
523
533
 
524
534
  guardrailVersion = guardrail_config.get("guardrailVersion", "")
525
535
  if guardrailVersion:
526
- self.add_internal_request_property(GUARDRAIL_VERSION, guardrailVersion)
536
+ self.add_internal_request_property(PayiPropertyNames.aws_bedrock_guardrail_version, guardrailVersion)
527
537
 
528
538
  if guardrailIdentifier and guardrailVersion and BedrockInstrumentor._guardrail_trace:
529
539
  trace = guardrail_config.get("trace", None)
@@ -597,9 +607,9 @@ class _BedrockConverseProviderRequest(_BedrockProviderRequest):
597
607
  def process_stop_reason(self, reason: str) -> None:
598
608
  if reason == "guardrail_intervened":
599
609
  # record both as a semantic failure and guardrail action so it is discoverable through both properties
600
- self.add_internal_request_property('system.failure', reason)
601
- self.add_internal_request_property('system.failure.description', GUARDRAIL_SEMANTIC_FAILURE_DESCRIPTION)
602
- self.add_internal_request_property(GUARDRAIL_ACTION, reason)
610
+ self.add_internal_request_property(PayiPropertyNames.failure, reason)
611
+ self.add_internal_request_property(PayiPropertyNames.failure_description, GUARDRAIL_SEMANTIC_FAILURE_DESCRIPTION)
612
+ self.add_internal_request_property(PayiPropertyNames.aws_bedrock_guardrail_action, reason)
603
613
 
604
614
  def bedrock_converse_process_streaming_for_function_call(request: _ProviderRequest, chunk: 'dict[str, Any]') -> None:
605
615
  contentBlockStart = chunk.get("contentBlockStart", {})
payi/lib/helpers.py CHANGED
@@ -25,6 +25,18 @@ class PayiCategories:
25
25
  aws_bedrock:str = "system.aws.bedrock"
26
26
  google_vertex:str = "system.google.vertex"
27
27
 
28
+ class PayiPropertyNames:
29
+ failure:str = "system.failure"
30
+ failure_description:str = "system.failure.description"
31
+
32
+ account_name:str = "system.account_name"
33
+ use_case_step:str = "system.use_case_step"
34
+ user_id:str = "system.user_id"
35
+
36
+ aws_bedrock_guardrail_id:str = "system.aws.bedrock.guardrail.id"
37
+ aws_bedrock_guardrail_version:str = "system.aws.bedrock.guardrail.version"
38
+ aws_bedrock_guardrail_action:str = "system.aws.bedrock.guardrail.action"
39
+
28
40
  def create_limit_header_from_ids(*, limit_ids: List[str]) -> Dict[str, str]:
29
41
  if not isinstance(limit_ids, list): # type: ignore
30
42
  raise TypeError("limit_ids must be a list")