payi 0.1.0a48__py3-none-any.whl → 0.1.0a49__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.48" # x-release-please-version
4
+ __version__ = "0.1.0-alpha.49" # x-release-please-version
@@ -88,6 +88,8 @@ async def achat_wrapper(
88
88
 
89
89
  def process_chunk(chunk: Any, ingest: IngestUnitsParams) -> None:
90
90
  if chunk.type == "message_start":
91
+ ingest["provider_response_id"] = chunk.message.id
92
+
91
93
  usage = chunk.message.usage
92
94
  units = ingest["units"]
93
95
 
@@ -128,7 +130,9 @@ def process_synchronous_response(response: Any, ingest: IngestUnitsParams, log_p
128
130
 
129
131
  if log_prompt_and_response:
130
132
  ingest["provider_response_json"] = response.to_json()
131
-
133
+
134
+ ingest["provider_response_id"] = response.id
135
+
132
136
  return None
133
137
 
134
138
  def has_image_and_get_texts(encoding: tiktoken.Encoding, content: Union[str, 'list[Any]']) -> 'tuple[bool, int]':
@@ -220,9 +220,9 @@ def process_synchronous_invoke_response(
220
220
 
221
221
  metadata = response.get("ResponseMetadata", {})
222
222
 
223
- # request_id = metadata.get("RequestId", "")
224
- # if request_id:
225
- # ingest["provider_request_id"] = request_id
223
+ request_id = metadata.get("RequestId", "")
224
+ if request_id:
225
+ ingest["provider_response_id"] = request_id
226
226
 
227
227
  response_headers = metadata.get("HTTPHeaders", {}).copy()
228
228
  if response_headers:
@@ -263,9 +263,9 @@ def process_synchronous_converse_response(
263
263
 
264
264
  metadata = response.get("ResponseMetadata", {})
265
265
 
266
- # request_id = metadata.get("RequestId", "")
267
- # if request_id:
268
- # ingest["provider_request_id"] = request_id
266
+ request_id = metadata.get("RequestId", "")
267
+ if request_id:
268
+ ingest["provider_response_id"] = request_id
269
269
 
270
270
  response_headers = metadata.get("HTTPHeaders", {})
271
271
  if response_headers:
@@ -144,10 +144,19 @@ def process_chat_synchronous_response(response: str, ingest: IngestUnitsParams,
144
144
  if log_prompt_and_response:
145
145
  ingest["provider_response_json"] = [json.dumps(response_dict)]
146
146
 
147
+ if "id" in response_dict:
148
+ ingest["provider_response_id"] = response_dict["id"]
149
+
147
150
  return None
148
151
 
149
152
  def process_chat_chunk(chunk: Any, ingest: IngestUnitsParams) -> None:
150
153
  model = model_to_dict(chunk)
154
+
155
+ if "provider_response_id" not in ingest:
156
+ response_id = model.get("id", None)
157
+ if response_id:
158
+ ingest["provider_response_id"] = response_id
159
+
151
160
  usage = model.get("usage")
152
161
  if usage:
153
162
  add_usage_units(usage, ingest["units"])
payi/lib/helpers.py CHANGED
@@ -1,5 +1,7 @@
1
+ from enum import Enum
1
2
  from typing import Dict, List, Union
2
3
 
4
+ PAYI_BASE_URL = "https://api.pay-i.com"
3
5
 
4
6
  class PayiHeaderNames:
5
7
  limit_ids:str = "xProxy-Limit-IDs"
@@ -10,6 +12,12 @@ class PayiHeaderNames:
10
12
  route_as_resource:str = "xProxy-RouteAs-Resource"
11
13
  provider_base_uri = "xProxy-Provider-BaseUri"
12
14
 
15
+ class PayiCategories(Enum):
16
+ anthropic = "system.anthropic"
17
+ openai = "system.openai"
18
+ azure_openai = "system.azureopenai"
19
+ aws_bedrock = "system.aws.bedrock"
20
+
13
21
  def create_limit_header_from_ids(limit_ids: List[str]) -> Dict[str, str]:
14
22
  if not isinstance(limit_ids, list): # type: ignore
15
23
  raise TypeError("limit_ids must be a list")
@@ -49,3 +57,23 @@ def create_headers(
49
57
  headers.update({ PayiHeaderNames.experience_name: experience_name})
50
58
 
51
59
  return headers
60
+
61
+ def payi_anthropic_url(payi_base_url: Union[str, None] = None) -> str:
62
+ if payi_base_url is None:
63
+ payi_base_url = PAYI_BASE_URL
64
+ return payi_base_url + "/api/v1/proxy/anthropic"
65
+
66
+ def payi_openai_url(payi_base_url: Union[str, None] = None) -> str:
67
+ if payi_base_url is None:
68
+ payi_base_url = PAYI_BASE_URL
69
+ return payi_base_url + "/api/v1/proxy/openai/v1"
70
+
71
+ def payi_azure_openai_url(payi_base_url: Union[str, None] = None) -> str:
72
+ if payi_base_url is None:
73
+ payi_base_url = PAYI_BASE_URL
74
+ return payi_base_url + "/api/v1/proxy/azure.openai"
75
+
76
+ def payi_aws_bedrock_url(payi_base_url: Union[str, None] = None) -> str:
77
+ if payi_base_url is None:
78
+ payi_base_url = PAYI_BASE_URL
79
+ return payi_base_url + "/api/v1/proxy/aws.bedrock"
payi/lib/instrument.py CHANGED
@@ -17,8 +17,8 @@ from payi.types.ingest_response import IngestResponse
17
17
  from payi.types.ingest_units_params import Units
18
18
  from payi.types.pay_i_common_models_api_router_header_info_param import PayICommonModelsAPIRouterHeaderInfoParam
19
19
 
20
+ from .helpers import PayiCategories
20
21
  from .Stopwatch import Stopwatch
21
- from .Instruments import Instruments
22
22
 
23
23
 
24
24
  class Context(TypedDict, total=False):
@@ -41,7 +41,7 @@ class PayiInstrumentor:
41
41
  self,
42
42
  payi: Optional[Payi],
43
43
  apayi: Optional[AsyncPayi],
44
- instruments: Union[Set[Instruments], None] = None,
44
+ instruments: Union[Set[PayiCategories], None] = None,
45
45
  log_prompt_and_response: bool = True,
46
46
  prompt_and_response_logger: Optional[
47
47
  Callable[[str, "dict[str, str]"], None]
@@ -56,7 +56,7 @@ class PayiInstrumentor:
56
56
  self._blocked_limits: set[str] = set()
57
57
  self._exceeded_limits: set[str] = set()
58
58
 
59
- if instruments is None or Instruments.ALL in instruments:
59
+ if instruments is None:
60
60
  self._instrument_all()
61
61
  else:
62
62
  self._instrument_specific(instruments)
@@ -66,12 +66,12 @@ class PayiInstrumentor:
66
66
  self._instrument_anthropic()
67
67
  self._instrument_aws_bedrock()
68
68
 
69
- def _instrument_specific(self, instruments: Set[Instruments]) -> None:
70
- if Instruments.OPENAI in instruments:
69
+ def _instrument_specific(self, instruments: Set[PayiCategories]) -> None:
70
+ if PayiCategories.openai in instruments or PayiCategories.azure_openai in instruments:
71
71
  self._instrument_openai()
72
- if Instruments.ANTHROPIC in instruments:
72
+ if PayiCategories.anthropic in instruments:
73
73
  self._instrument_anthropic()
74
- if Instruments.AWS_BEDROCK in instruments:
74
+ if PayiCategories.aws_bedrock in instruments:
75
75
  self._instrument_aws_bedrock()
76
76
 
77
77
  def _instrument_openai(self) -> None:
@@ -736,7 +736,9 @@ class ChatStreamWrapper(ObjectProxy): # type: ignore
736
736
 
737
737
  bedrock_from_stream: bool = False
738
738
  if is_bedrock:
739
+ ingest["provider_response_id"] = response["ResponseMetadata"]["RequestId"]
739
740
  stream = response.get("stream", None)
741
+
740
742
  if stream:
741
743
  response = stream
742
744
  bedrock_from_stream = True
@@ -862,7 +864,7 @@ _instrumentor: Optional[PayiInstrumentor] = None
862
864
 
863
865
  def payi_instrument(
864
866
  payi: Optional[Union[Payi, AsyncPayi, 'list[Union[Payi, AsyncPayi]]']] = None,
865
- instruments: Optional[Set[Instruments]] = None,
867
+ instruments: Optional[Set[PayiCategories]] = None,
866
868
  log_prompt_and_response: bool = True,
867
869
  prompt_and_response_logger: Optional[Callable[[str, "dict[str, str]"], None]] = None,
868
870
  ) -> None:
payi/resources/ingest.py CHANGED
@@ -97,6 +97,7 @@ class IngestResource(SyncAPIResource):
97
97
  provider_request_headers: Optional[Iterable[PayICommonModelsAPIRouterHeaderInfoParam]] | NotGiven = NOT_GIVEN,
98
98
  provider_request_json: Optional[str] | NotGiven = NOT_GIVEN,
99
99
  provider_response_headers: Optional[Iterable[PayICommonModelsAPIRouterHeaderInfoParam]] | NotGiven = NOT_GIVEN,
100
+ provider_response_id: Optional[str] | NotGiven = NOT_GIVEN,
100
101
  provider_response_json: Union[str, List[str], None] | NotGiven = NOT_GIVEN,
101
102
  provider_uri: Optional[str] | NotGiven = NOT_GIVEN,
102
103
  time_to_first_token_ms: Optional[int] | NotGiven = NOT_GIVEN,
@@ -201,6 +202,7 @@ class IngestResource(SyncAPIResource):
201
202
  "provider_request_headers": provider_request_headers,
202
203
  "provider_request_json": provider_request_json,
203
204
  "provider_response_headers": provider_response_headers,
205
+ "provider_response_id": provider_response_id,
204
206
  "provider_response_json": provider_response_json,
205
207
  "provider_uri": provider_uri,
206
208
  "time_to_first_token_ms": time_to_first_token_ms,
@@ -280,6 +282,7 @@ class AsyncIngestResource(AsyncAPIResource):
280
282
  provider_request_headers: Optional[Iterable[PayICommonModelsAPIRouterHeaderInfoParam]] | NotGiven = NOT_GIVEN,
281
283
  provider_request_json: Optional[str] | NotGiven = NOT_GIVEN,
282
284
  provider_response_headers: Optional[Iterable[PayICommonModelsAPIRouterHeaderInfoParam]] | NotGiven = NOT_GIVEN,
285
+ provider_response_id: Optional[str] | NotGiven = NOT_GIVEN,
283
286
  provider_response_json: Union[str, List[str], None] | NotGiven = NOT_GIVEN,
284
287
  provider_uri: Optional[str] | NotGiven = NOT_GIVEN,
285
288
  time_to_first_token_ms: Optional[int] | NotGiven = NOT_GIVEN,
@@ -383,6 +386,7 @@ class AsyncIngestResource(AsyncAPIResource):
383
386
  "provider_request_headers": provider_request_headers,
384
387
  "provider_request_json": provider_request_json,
385
388
  "provider_response_headers": provider_response_headers,
389
+ "provider_response_id": provider_response_id,
386
390
  "provider_response_json": provider_response_json,
387
391
  "provider_uri": provider_uri,
388
392
  "time_to_first_token_ms": time_to_first_token_ms,
@@ -49,6 +49,8 @@ class IngestEventParam(TypedDict, total=False):
49
49
 
50
50
  provider_response_headers: Optional[Iterable[PayICommonModelsAPIRouterHeaderInfoParam]]
51
51
 
52
+ provider_response_id: Optional[str]
53
+
52
54
  provider_response_json: Union[str, List[str], None]
53
55
 
54
56
  provider_uri: Optional[str]
@@ -35,6 +35,8 @@ class IngestUnitsParams(TypedDict, total=False):
35
35
 
36
36
  provider_response_headers: Optional[Iterable[PayICommonModelsAPIRouterHeaderInfoParam]]
37
37
 
38
+ provider_response_id: Optional[str]
39
+
38
40
  provider_response_json: Union[str, List[str], None]
39
41
 
40
42
  provider_uri: Optional[str]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: payi
3
- Version: 0.1.0a48
3
+ Version: 0.1.0a49
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=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=GtYbN-yExify_mgm02kxxAg7YrHlP8HnvMwXvPXKAn4,165
14
+ payi/_version.py,sha256=rmhSv-iqFMLwhHLJFziU4UexjO1cgGNYoRU7D4BYZBc,165
15
15
  payi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  payi/_utils/__init__.py,sha256=PNZ_QJuzZEgyYXqkO1HVhGkj5IU9bglVUcw7H-Knjzw,2062
17
17
  payi/_utils/_logs.py,sha256=fmnf5D9TOgkgZKfgYmSa3PiUc3SZgkchn6CzJUeo0SQ,768
@@ -23,16 +23,15 @@ payi/_utils/_transform.py,sha256=tsSFOIZ7iczaUsMSGBD_iSFOOdUyT2xtkcq1xyF0L9o,139
23
23
  payi/_utils/_typing.py,sha256=nTJz0jcrQbEgxwy4TtAkNxuU0QHHlmc6mQtA6vIR8tg,4501
24
24
  payi/_utils/_utils.py,sha256=8UmbPOy_AAr2uUjjFui-VZSrVBHRj6bfNEKRp5YZP2A,12004
25
25
  payi/lib/.keep,sha256=wuNrz-5SXo3jJaJOJgz4vFHM41YH_g20F5cRQo0vLes,224
26
- payi/lib/AnthropicInstrumentor.py,sha256=1dJTFs5WfPxbIjWcYV2tP3kiYc4g3WyyyR4XWQ-WI_g,5300
27
- payi/lib/BedrockInstrumentor.py,sha256=B5deT8TcUvOsRdIewbbHtsxTS7_oHJ05ZUIdFziWf8E,10082
28
- payi/lib/Instruments.py,sha256=bapmVS9jbHtFknXCKDzsFFWvf5XLtzEpdlvI7iEWY-o,147
29
- payi/lib/OpenAIInstrumentor.py,sha256=rxu5wOUBZaGwFjUoUhk5UDeTcYSmmO6BVgnXL4yYb08,6613
26
+ payi/lib/AnthropicInstrumentor.py,sha256=h-yebG7r7cSRVM_utva55Gc4BVcoW6WGrQrDg55mZQ0,5417
27
+ payi/lib/BedrockInstrumentor.py,sha256=4WSZLzLHMv-5U1OFr0ZErESNHTyPHn0kHATUw4HTDkQ,10072
28
+ payi/lib/OpenAIInstrumentor.py,sha256=ZUu-Byhz7AXhvxjOMdX8tB2JOpM5sCj0KnyRB49lQg0,6881
30
29
  payi/lib/Stopwatch.py,sha256=7OJlxvr2Jyb6Zr1LYCYKczRB7rDVKkIR7gc4YoleNdE,764
31
- payi/lib/helpers.py,sha256=RRJ0esC8T-b6n9Bc_WbUHMlucdv_ARhiV3oiAAUg-KU,1915
32
- payi/lib/instrument.py,sha256=HgKyy7nAWf0X66VuBJtc87J5eokGjnGcm-Hq0IOmgzA,36185
30
+ payi/lib/helpers.py,sha256=fcT6gAHUP77YaLmgw9HWdIyTDJPI72weUsUVDGW0CbE,2929
31
+ payi/lib/instrument.py,sha256=oJdF1ocd-wbQgNF9MIZWAaGDInzbu4TRy9946GVRuvI,36302
33
32
  payi/resources/__init__.py,sha256=isHGXSl9kOrZDduKrX3UenTwrdTpuKJVBjw6NYSBV20,3592
34
33
  payi/resources/billing_models.py,sha256=5w3RfGXtGlyq5vbTw6hQrx1UlzRBtlq8ArcFlf5e3TY,20152
35
- payi/resources/ingest.py,sha256=xdVD0fHGkVpsgqxNTkly_X7UdLyWLNb9_uU8tzWB5Jc,18430
34
+ payi/resources/ingest.py,sha256=Ti-wnHj_A0_h3LxybPIahmxfsBTPG60ndnyCJZRJybo,18698
36
35
  payi/resources/price_modifiers.py,sha256=t-k2F_zf2FhoxiqDHAPBPvhSgTjewlJqh50y58FNMuw,13475
37
36
  payi/resources/categories/__init__.py,sha256=w5gMiPdBSzJA_qfoVtFBElaoe8wGf_O63R7R1Spr6Gk,1093
38
37
  payi/resources/categories/categories.py,sha256=FohmajDcadMXzhG3Z1HKGkbSImO7rhzQ0olZXHz8z48,16074
@@ -67,9 +66,9 @@ payi/types/cost_details.py,sha256=w9p79opEG3kcsjkRRP7niaMcUswdfB4Y7HCkVTcQ1zQ,30
67
66
  payi/types/default_response.py,sha256=o617LpRsCIZHCZxAc5nVI2JQ3HPGZo4gCDvSDkxkIJ8,270
68
67
  payi/types/experience_instance_response.py,sha256=N07MH6hjs1ISHLVpR2FG-u4awsZ_GGi97UNMXAWV1yA,296
69
68
  payi/types/ingest_bulk_params.py,sha256=d76YwiXaNeltLS3w86ZxLzTKGa7ymGLJDSelaMQGf8Y,382
70
- payi/types/ingest_event_param.py,sha256=wA9YuiQceNL3veHO_rVuKZg9o-EB1WLoz0aaF6Wcm-k,1498
69
+ payi/types/ingest_event_param.py,sha256=IoOQuEEafJtWmXWsBbRCMbt16PXQR_nscnEEIRsEC1s,1539
71
70
  payi/types/ingest_response.py,sha256=KZfsgUhC942QkkjDFMqjJwCRoO2vkXv-Sx3X_xjijfg,1449
72
- payi/types/ingest_units_params.py,sha256=0s_j6268ZmeXDw9lQ_HKLldA_EvNyPcOxM6kFxLwxkA,1749
71
+ payi/types/ingest_units_params.py,sha256=bPEo-bTlTrboi24gAlxw7jTBeB1ZoLI59ZgcuwDq_bg,1790
73
72
  payi/types/limit_create_params.py,sha256=Av8oMCxlKH7VB2MtYN5-25rAjqDDTPHjsXIQ2xubmck,549
74
73
  payi/types/limit_history_response.py,sha256=sCx2qKBiHU9X2KrYWV8NZiarYMGurof5GF4QobR2-EU,787
75
74
  payi/types/limit_list_params.py,sha256=iWM67oL53y2IZ7D3Gyy8mdYv-B7vF-rbmRFn7SBUnJk,364
@@ -113,7 +112,7 @@ payi/types/requests/request_result.py,sha256=phYQiqhwNaR9igP-Fhs34Y-__dlT7L4wq-r
113
112
  payi/types/shared/__init__.py,sha256=-xz5dxK5LBjLnsi2LpLq5btaGDFp-mSjJ0y2qKy0Yus,264
114
113
  payi/types/shared/evaluation_response.py,sha256=ejEToMA57PUu1SldEtJ5z9r4fAO3U0tvdjbsyIoVX1s,214
115
114
  payi/types/shared/pay_i_common_models_budget_management_cost_details_base.py,sha256=XmIzJXy4zAi-mfrDvEXiYjO3qF1EvugGUl-Gijj4TA4,268
116
- payi-0.1.0a48.dist-info/METADATA,sha256=gjbFkoar2_1p61b6hr0bDBVmtEHaaNKdw5LGrqLwLiE,12660
117
- payi-0.1.0a48.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
118
- payi-0.1.0a48.dist-info/licenses/LICENSE,sha256=CQt03aM-P4a3Yg5qBg3JSLVoQS3smMyvx7tYg_6V7Gk,11334
119
- payi-0.1.0a48.dist-info/RECORD,,
115
+ payi-0.1.0a49.dist-info/METADATA,sha256=e8-FDTdXNFG7JPg5LR1eCGn3h-uaeiHKF-UwNKQJEHM,12660
116
+ payi-0.1.0a49.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
117
+ payi-0.1.0a49.dist-info/licenses/LICENSE,sha256=CQt03aM-P4a3Yg5qBg3JSLVoQS3smMyvx7tYg_6V7Gk,11334
118
+ payi-0.1.0a49.dist-info/RECORD,,
payi/lib/Instruments.py DELETED
@@ -1,8 +0,0 @@
1
- from enum import Enum
2
-
3
-
4
- class Instruments(Enum):
5
- ALL = "all"
6
- OPENAI = "openai"
7
- ANTHROPIC = "anthropic"
8
- AWS_BEDROCK = "aws.bedrock"