payi 0.1.0a110__py3-none-any.whl → 0.1.0a137__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.
- payi/__init__.py +3 -1
- payi/_base_client.py +12 -12
- payi/_client.py +8 -8
- payi/_compat.py +48 -48
- payi/_models.py +87 -59
- payi/_qs.py +7 -7
- payi/_streaming.py +4 -6
- payi/_types.py +53 -12
- payi/_utils/__init__.py +9 -2
- payi/_utils/_compat.py +45 -0
- payi/_utils/_datetime_parse.py +136 -0
- payi/_utils/_sync.py +3 -31
- payi/_utils/_transform.py +13 -3
- payi/_utils/_typing.py +6 -1
- payi/_utils/_utils.py +5 -6
- payi/_version.py +1 -1
- payi/lib/AnthropicInstrumentor.py +83 -57
- payi/lib/BedrockInstrumentor.py +292 -57
- payi/lib/GoogleGenAiInstrumentor.py +18 -31
- payi/lib/OpenAIInstrumentor.py +56 -72
- payi/lib/ProviderRequest.py +216 -0
- payi/lib/StreamWrappers.py +379 -0
- payi/lib/VertexInstrumentor.py +18 -37
- payi/lib/VertexRequest.py +16 -2
- payi/lib/data/cohere_embed_english_v3.json +30706 -0
- payi/lib/helpers.py +53 -1
- payi/lib/instrument.py +404 -668
- payi/resources/categories/__init__.py +0 -14
- payi/resources/categories/categories.py +25 -53
- payi/resources/categories/resources.py +27 -23
- payi/resources/ingest.py +126 -132
- payi/resources/limits/__init__.py +14 -14
- payi/resources/limits/limits.py +58 -58
- payi/resources/limits/properties.py +171 -0
- payi/resources/requests/request_id/properties.py +8 -8
- payi/resources/requests/request_id/result.py +3 -3
- payi/resources/requests/response_id/properties.py +8 -8
- payi/resources/requests/response_id/result.py +3 -3
- payi/resources/use_cases/definitions/definitions.py +27 -27
- payi/resources/use_cases/definitions/kpis.py +23 -23
- payi/resources/use_cases/definitions/limit_config.py +14 -14
- payi/resources/use_cases/definitions/version.py +3 -3
- payi/resources/use_cases/kpis.py +15 -15
- payi/resources/use_cases/properties.py +6 -6
- payi/resources/use_cases/use_cases.py +7 -7
- payi/types/__init__.py +2 -0
- payi/types/bulk_ingest_response.py +3 -20
- payi/types/categories/__init__.py +0 -1
- payi/types/categories/resource_list_params.py +5 -1
- payi/types/category_list_resources_params.py +5 -1
- payi/types/category_resource_response.py +31 -1
- payi/types/ingest_event_param.py +7 -6
- payi/types/ingest_units_params.py +5 -4
- payi/types/limit_create_params.py +3 -3
- payi/types/limit_list_response.py +1 -3
- payi/types/limit_response.py +1 -3
- payi/types/limits/__init__.py +2 -9
- payi/types/limits/{tag_remove_params.py → property_update_params.py} +4 -5
- payi/types/limits/{tag_delete_response.py → property_update_response.py} +3 -3
- payi/types/requests/request_id/property_update_params.py +2 -2
- payi/types/requests/response_id/property_update_params.py +2 -2
- payi/types/shared/__init__.py +2 -0
- payi/types/shared/api_error.py +18 -0
- payi/types/shared/pay_i_common_models_budget_management_create_limit_base.py +3 -3
- payi/types/shared/properties_request.py +11 -0
- payi/types/shared/xproxy_result.py +2 -0
- payi/types/shared_params/pay_i_common_models_budget_management_create_limit_base.py +3 -3
- payi/types/use_cases/definitions/limit_config_create_params.py +3 -3
- payi/types/use_cases/property_update_params.py +2 -2
- {payi-0.1.0a110.dist-info → payi-0.1.0a137.dist-info}/METADATA +6 -6
- {payi-0.1.0a110.dist-info → payi-0.1.0a137.dist-info}/RECORD +73 -75
- payi/resources/categories/fixed_cost_resources.py +0 -196
- payi/resources/limits/tags.py +0 -507
- payi/types/categories/fixed_cost_resource_create_params.py +0 -21
- payi/types/limits/limit_tags.py +0 -16
- payi/types/limits/tag_create_params.py +0 -13
- payi/types/limits/tag_create_response.py +0 -10
- payi/types/limits/tag_list_response.py +0 -10
- payi/types/limits/tag_remove_response.py +0 -10
- payi/types/limits/tag_update_params.py +0 -13
- payi/types/limits/tag_update_response.py +0 -10
- {payi-0.1.0a110.dist-info → payi-0.1.0a137.dist-info}/WHEEL +0 -0
- {payi-0.1.0a110.dist-info → payi-0.1.0a137.dist-info}/licenses/LICENSE +0 -0
payi/lib/helpers.py
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
import os
|
|
2
|
-
|
|
4
|
+
import json
|
|
5
|
+
from typing import Any, Dict, List, Union
|
|
6
|
+
|
|
7
|
+
__all__ = ['_set_attr_safe']
|
|
3
8
|
|
|
4
9
|
PAYI_BASE_URL = "https://api.pay-i.com"
|
|
5
10
|
|
|
6
11
|
class PayiHeaderNames:
|
|
7
12
|
limit_ids:str = "xProxy-Limit-IDs"
|
|
8
13
|
request_tags:str = "xProxy-Request-Tags"
|
|
14
|
+
request_properties:str = "xProxy-Request-Properties"
|
|
9
15
|
use_case_id:str = "xProxy-UseCase-ID"
|
|
10
16
|
use_case_name:str = "xProxy-UseCase-Name"
|
|
11
17
|
use_case_version:str = "xProxy-UseCase-Version"
|
|
12
18
|
use_case_step:str = "xProxy-UseCase-Step"
|
|
19
|
+
use_case_properties:str = "xProxy-UseCase-Properties"
|
|
13
20
|
user_id:str = "xProxy-User-ID"
|
|
14
21
|
account_name:str = "xProxy-Account-Name"
|
|
15
22
|
price_as_category:str = "xProxy-PriceAs-Category"
|
|
@@ -25,6 +32,23 @@ class PayiCategories:
|
|
|
25
32
|
aws_bedrock:str = "system.aws.bedrock"
|
|
26
33
|
google_vertex:str = "system.google.vertex"
|
|
27
34
|
|
|
35
|
+
class PayiPropertyNames:
|
|
36
|
+
failure:str = "system.failure"
|
|
37
|
+
failure_description:str = "system.failure.description"
|
|
38
|
+
|
|
39
|
+
account_name:str = "system.account_name"
|
|
40
|
+
use_case_step:str = "system.use_case_step"
|
|
41
|
+
user_id:str = "system.user_id"
|
|
42
|
+
|
|
43
|
+
aws_bedrock_guardrail_id:str = "system.aws.bedrock.guardrail.id"
|
|
44
|
+
aws_bedrock_guardrail_version:str = "system.aws.bedrock.guardrail.version"
|
|
45
|
+
aws_bedrock_guardrail_action:str = "system.aws.bedrock.guardrail.action"
|
|
46
|
+
|
|
47
|
+
class PayiResourceScopes:
|
|
48
|
+
global_scope: str = "global"
|
|
49
|
+
datazone_scope: str = "datazone"
|
|
50
|
+
region_scope: str = "region"
|
|
51
|
+
|
|
28
52
|
def create_limit_header_from_ids(*, limit_ids: List[str]) -> Dict[str, str]:
|
|
29
53
|
if not isinstance(limit_ids, list): # type: ignore
|
|
30
54
|
raise TypeError("limit_ids must be a list")
|
|
@@ -41,6 +65,9 @@ def create_request_header_from_tags(*, request_tags: List[str]) -> Dict[str, str
|
|
|
41
65
|
|
|
42
66
|
return { PayiHeaderNames.request_tags: ",".join(valid_tags) } if valid_tags else {}
|
|
43
67
|
|
|
68
|
+
def _compact_json(data: Any) -> str:
|
|
69
|
+
return json.dumps(data, separators=(',', ':'))
|
|
70
|
+
|
|
44
71
|
def create_headers(
|
|
45
72
|
*,
|
|
46
73
|
limit_ids: Union[List[str], None] = None,
|
|
@@ -51,6 +78,8 @@ def create_headers(
|
|
|
51
78
|
use_case_name: Union[str, None] = None,
|
|
52
79
|
use_case_version: Union[int, None] = None,
|
|
53
80
|
use_case_step: Union[str, None] = None,
|
|
81
|
+
use_case_properties: Union[Dict[str, str], None] = None,
|
|
82
|
+
request_properties: Union[Dict[str, str], None] = None,
|
|
54
83
|
price_as_category: Union[str, None] = None,
|
|
55
84
|
price_as_resource: Union[str, None] = None,
|
|
56
85
|
resource_scope: Union[str, None] = None,
|
|
@@ -71,6 +100,10 @@ def create_headers(
|
|
|
71
100
|
headers.update({ PayiHeaderNames.use_case_name: use_case_name})
|
|
72
101
|
if use_case_version:
|
|
73
102
|
headers.update({ PayiHeaderNames.use_case_version: str(use_case_version)})
|
|
103
|
+
if use_case_properties:
|
|
104
|
+
headers.update({ PayiHeaderNames.use_case_properties: _compact_json(use_case_properties) })
|
|
105
|
+
if request_properties:
|
|
106
|
+
headers.update({ PayiHeaderNames.request_properties: _compact_json(request_properties) })
|
|
74
107
|
if use_case_step:
|
|
75
108
|
headers.update({ PayiHeaderNames.use_case_step: use_case_step})
|
|
76
109
|
if price_as_category:
|
|
@@ -106,3 +139,22 @@ def payi_aws_bedrock_url(payi_base_url: Union[str, None] = None) -> str:
|
|
|
106
139
|
|
|
107
140
|
# def payi_google_vertex_url(payi_base_url: Union[str, None] = None) -> str:
|
|
108
141
|
# return _resolve_payi_base_url(payi_base_url=payi_base_url) + "/api/v1/proxy/google.vertex"
|
|
142
|
+
|
|
143
|
+
def _set_attr_safe(o: Any, attr_name: str, attr_value: Any) -> None:
|
|
144
|
+
try:
|
|
145
|
+
if hasattr(o, '__pydantic_private__') and o.__pydantic_private__ is not None:
|
|
146
|
+
o.__pydantic_private__[attr_name] = attr_value
|
|
147
|
+
|
|
148
|
+
if hasattr(o, '__dict__'):
|
|
149
|
+
# Use object.__setattr__ to bypass Pydantic validation
|
|
150
|
+
# This allows setting attributes outside the model schema without triggering forbid=true errors
|
|
151
|
+
object.__setattr__(o, attr_name, attr_value)
|
|
152
|
+
elif isinstance(o, dict):
|
|
153
|
+
o[attr_name] = attr_value
|
|
154
|
+
else:
|
|
155
|
+
setattr(o, attr_name, attr_value)
|
|
156
|
+
|
|
157
|
+
except Exception:
|
|
158
|
+
# _g_logger.debug(f"Could not set attribute {attr_name}: {e}")
|
|
159
|
+
pass
|
|
160
|
+
|