payi 0.1.0a59__py3-none-any.whl → 0.1.0a61__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 +1 -1
- payi/lib/AnthropicInstrumentor.py +11 -11
- payi/lib/BedrockInstrumentor.py +15 -15
- payi/lib/OpenAIInstrumentor.py +16 -16
- payi/lib/helpers.py +16 -12
- payi/lib/instrument.py +180 -39
- payi/pagination.py +50 -0
- payi/resources/categories/categories.py +108 -23
- payi/resources/categories/resources.py +42 -12
- payi/resources/experiences/types/types.py +37 -17
- payi/resources/limits/limits.py +21 -30
- payi/resources/use_cases/__init__.py +14 -0
- payi/resources/use_cases/definitions/__init__.py +14 -0
- payi/resources/use_cases/definitions/definitions.py +68 -18
- payi/resources/use_cases/definitions/kpis.py +584 -0
- payi/resources/use_cases/kpis.py +469 -0
- payi/resources/use_cases/use_cases.py +32 -0
- payi/types/__init__.py +3 -3
- payi/types/categories/__init__.py +1 -1
- payi/types/categories/resource_list_params.py +17 -0
- payi/types/category_list_params.py +15 -0
- payi/types/category_list_resources_params.py +15 -0
- payi/types/category_response.py +0 -5
- payi/types/experiences/__init__.py +0 -1
- payi/types/experiences/type_list_params.py +6 -1
- payi/types/limit_list_params.py +4 -13
- payi/types/limit_list_response.py +30 -0
- payi/types/use_cases/__init__.py +4 -1
- payi/types/use_cases/definition_list_params.py +6 -1
- payi/types/use_cases/definitions/__init__.py +8 -0
- payi/types/use_cases/definitions/kpi_create_params.py +17 -0
- payi/types/use_cases/definitions/kpi_create_response.py +20 -0
- payi/types/use_cases/definitions/kpi_delete_response.py +20 -0
- payi/types/use_cases/definitions/kpi_list_params.py +17 -0
- payi/types/use_cases/definitions/kpi_list_response.py +20 -0
- payi/types/use_cases/definitions/kpi_retrieve_response.py +20 -0
- payi/types/use_cases/definitions/kpi_update_params.py +16 -0
- payi/types/use_cases/definitions/kpi_update_response.py +20 -0
- payi/types/use_cases/kpi_create_params.py +13 -0
- payi/types/use_cases/kpi_list_params.py +17 -0
- payi/types/use_cases/kpi_list_response.py +21 -0
- payi/types/use_cases/kpi_update_params.py +13 -0
- {payi-0.1.0a59.dist-info → payi-0.1.0a61.dist-info}/METADATA +91 -28
- {payi-0.1.0a59.dist-info → payi-0.1.0a61.dist-info}/RECORD +46 -33
- payi/types/categories/resource_list_response.py +0 -10
- payi/types/category_list_resources_response.py +0 -10
- payi/types/category_list_response.py +0 -10
- payi/types/experiences/type_list_response.py +0 -10
- payi/types/paged_limit_list.py +0 -52
- payi/types/use_cases/definition_list_response.py +0 -10
- {payi-0.1.0a59.dist-info → payi-0.1.0a61.dist-info}/WHEEL +0 -0
- {payi-0.1.0a59.dist-info → payi-0.1.0a61.dist-info}/licenses/LICENSE +0 -0
payi/_version.py
CHANGED
|
@@ -7,12 +7,12 @@ from wrapt import wrap_function_wrapper # type: ignore
|
|
|
7
7
|
from payi.types import IngestUnitsParams
|
|
8
8
|
from payi.types.ingest_units_params import Units
|
|
9
9
|
|
|
10
|
-
from .instrument import
|
|
10
|
+
from .instrument import _IsStreaming, _PayiInstrumentor
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class AnthropicIntrumentor:
|
|
14
14
|
@staticmethod
|
|
15
|
-
def instrument(instrumentor:
|
|
15
|
+
def instrument(instrumentor: _PayiInstrumentor) -> None:
|
|
16
16
|
try:
|
|
17
17
|
import anthropic # type: ignore # noqa: F401 I001
|
|
18
18
|
|
|
@@ -45,9 +45,9 @@ class AnthropicIntrumentor:
|
|
|
45
45
|
return
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
@
|
|
48
|
+
@_PayiInstrumentor.payi_wrapper
|
|
49
49
|
def chat_wrapper(
|
|
50
|
-
instrumentor:
|
|
50
|
+
instrumentor: _PayiInstrumentor,
|
|
51
51
|
wrapped: Any,
|
|
52
52
|
instance: Any,
|
|
53
53
|
*args: Any,
|
|
@@ -58,16 +58,16 @@ def chat_wrapper(
|
|
|
58
58
|
process_chunk,
|
|
59
59
|
process_request,
|
|
60
60
|
process_synchronous_response,
|
|
61
|
-
|
|
61
|
+
_IsStreaming.kwargs,
|
|
62
62
|
wrapped,
|
|
63
63
|
instance,
|
|
64
64
|
args,
|
|
65
65
|
kwargs,
|
|
66
66
|
)
|
|
67
67
|
|
|
68
|
-
@
|
|
68
|
+
@_PayiInstrumentor.payi_awrapper
|
|
69
69
|
async def achat_wrapper(
|
|
70
|
-
instrumentor:
|
|
70
|
+
instrumentor: _PayiInstrumentor,
|
|
71
71
|
wrapped: Any,
|
|
72
72
|
instance: Any,
|
|
73
73
|
*args: Any,
|
|
@@ -78,7 +78,7 @@ async def achat_wrapper(
|
|
|
78
78
|
process_chunk,
|
|
79
79
|
process_request,
|
|
80
80
|
process_synchronous_response,
|
|
81
|
-
|
|
81
|
+
_IsStreaming.kwargs,
|
|
82
82
|
wrapped,
|
|
83
83
|
instance,
|
|
84
84
|
args,
|
|
@@ -93,7 +93,7 @@ def process_chunk(chunk: Any, ingest: IngestUnitsParams) -> None:
|
|
|
93
93
|
usage = chunk.message.usage
|
|
94
94
|
units = ingest["units"]
|
|
95
95
|
|
|
96
|
-
input =
|
|
96
|
+
input = _PayiInstrumentor.update_for_vision(usage.input_tokens, units)
|
|
97
97
|
|
|
98
98
|
units["text"] = Units(input=input, output=0)
|
|
99
99
|
|
|
@@ -124,7 +124,7 @@ def process_synchronous_response(response: Any, ingest: IngestUnitsParams, log_p
|
|
|
124
124
|
text_cache_read = usage.cache_read_input_tokens
|
|
125
125
|
units["text_cache_read"] = Units(input=text_cache_read, output=0)
|
|
126
126
|
|
|
127
|
-
input =
|
|
127
|
+
input = _PayiInstrumentor.update_for_vision(input, units)
|
|
128
128
|
|
|
129
129
|
units["text"] = Units(input=input, output=output)
|
|
130
130
|
|
|
@@ -165,4 +165,4 @@ def process_request(ingest: IngestUnitsParams, *args: Any, **kwargs: Any) -> Non
|
|
|
165
165
|
if not has_image or estimated_token_count == 0:
|
|
166
166
|
return
|
|
167
167
|
|
|
168
|
-
ingest["units"][
|
|
168
|
+
ingest["units"][_PayiInstrumentor.estimated_prompt_tokens] = Units(input=estimated_token_count, output=0)
|
payi/lib/BedrockInstrumentor.py
CHANGED
|
@@ -8,12 +8,12 @@ from wrapt import ObjectProxy, wrap_function_wrapper # type: ignore
|
|
|
8
8
|
from payi.types.ingest_units_params import Units, IngestUnitsParams
|
|
9
9
|
from payi.types.pay_i_common_models_api_router_header_info_param import PayICommonModelsAPIRouterHeaderInfoParam
|
|
10
10
|
|
|
11
|
-
from .instrument import
|
|
11
|
+
from .instrument import _IsStreaming, _PayiInstrumentor
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
class BedrockInstrumentor:
|
|
15
15
|
@staticmethod
|
|
16
|
-
def instrument(instrumentor:
|
|
16
|
+
def instrument(instrumentor: _PayiInstrumentor) -> None:
|
|
17
17
|
try:
|
|
18
18
|
import boto3 # type: ignore # noqa: F401 I001
|
|
19
19
|
|
|
@@ -33,8 +33,8 @@ class BedrockInstrumentor:
|
|
|
33
33
|
logging.debug(f"Error instrumenting bedrock: {e}")
|
|
34
34
|
return
|
|
35
35
|
|
|
36
|
-
@
|
|
37
|
-
def create_client_wrapper(instrumentor:
|
|
36
|
+
@_PayiInstrumentor.payi_wrapper
|
|
37
|
+
def create_client_wrapper(instrumentor: _PayiInstrumentor, wrapped: Any, instance: Any, *args: Any, **kwargs: Any) -> Any: # noqa: ARG001
|
|
38
38
|
if kwargs.get("service_name") != "bedrock-runtime":
|
|
39
39
|
return wrapped(*args, **kwargs)
|
|
40
40
|
|
|
@@ -55,7 +55,7 @@ class InvokeResponseWrapper(ObjectProxy): # type: ignore
|
|
|
55
55
|
def __init__(
|
|
56
56
|
self,
|
|
57
57
|
response: Any,
|
|
58
|
-
instrumentor:
|
|
58
|
+
instrumentor: _PayiInstrumentor,
|
|
59
59
|
ingest: IngestUnitsParams,
|
|
60
60
|
log_prompt_and_response: bool
|
|
61
61
|
) -> None:
|
|
@@ -95,7 +95,7 @@ class InvokeResponseWrapper(ObjectProxy): # type: ignore
|
|
|
95
95
|
|
|
96
96
|
return data
|
|
97
97
|
|
|
98
|
-
def wrap_invoke(instrumentor:
|
|
98
|
+
def wrap_invoke(instrumentor: _PayiInstrumentor, wrapped: Any) -> Any:
|
|
99
99
|
@wraps(wrapped)
|
|
100
100
|
def invoke_wrapper(*args: Any, **kwargs: 'dict[str, Any]') -> Any:
|
|
101
101
|
modelId:str = kwargs.get("modelId", "") # type: ignore
|
|
@@ -106,7 +106,7 @@ def wrap_invoke(instrumentor: PayiInstrumentor, wrapped: Any) -> Any:
|
|
|
106
106
|
None,
|
|
107
107
|
process_invoke_request,
|
|
108
108
|
process_synchronous_invoke_response,
|
|
109
|
-
|
|
109
|
+
_IsStreaming.false,
|
|
110
110
|
wrapped,
|
|
111
111
|
None,
|
|
112
112
|
args,
|
|
@@ -116,7 +116,7 @@ def wrap_invoke(instrumentor: PayiInstrumentor, wrapped: Any) -> Any:
|
|
|
116
116
|
|
|
117
117
|
return invoke_wrapper
|
|
118
118
|
|
|
119
|
-
def wrap_invoke_stream(instrumentor:
|
|
119
|
+
def wrap_invoke_stream(instrumentor: _PayiInstrumentor, wrapped: Any) -> Any:
|
|
120
120
|
@wraps(wrapped)
|
|
121
121
|
def invoke_wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
122
122
|
modelId:str = kwargs.get("modelId", "") # type: ignore
|
|
@@ -127,7 +127,7 @@ def wrap_invoke_stream(instrumentor: PayiInstrumentor, wrapped: Any) -> Any:
|
|
|
127
127
|
process_invoke_streaming_anthropic_chunk if modelId.startswith("anthropic.") else process_invoke_streaming_llama_chunk,
|
|
128
128
|
process_invoke_request,
|
|
129
129
|
None,
|
|
130
|
-
|
|
130
|
+
_IsStreaming.true,
|
|
131
131
|
wrapped,
|
|
132
132
|
None,
|
|
133
133
|
args,
|
|
@@ -137,7 +137,7 @@ def wrap_invoke_stream(instrumentor: PayiInstrumentor, wrapped: Any) -> Any:
|
|
|
137
137
|
|
|
138
138
|
return invoke_wrapper
|
|
139
139
|
|
|
140
|
-
def wrap_converse(instrumentor:
|
|
140
|
+
def wrap_converse(instrumentor: _PayiInstrumentor, wrapped: Any) -> Any:
|
|
141
141
|
@wraps(wrapped)
|
|
142
142
|
def invoke_wrapper(*args: Any, **kwargs: 'dict[str, Any]') -> Any:
|
|
143
143
|
modelId:str = kwargs.get("modelId", "") # type: ignore
|
|
@@ -148,7 +148,7 @@ def wrap_converse(instrumentor: PayiInstrumentor, wrapped: Any) -> Any:
|
|
|
148
148
|
None,
|
|
149
149
|
process_converse_request,
|
|
150
150
|
process_synchronous_converse_response,
|
|
151
|
-
|
|
151
|
+
_IsStreaming.false,
|
|
152
152
|
wrapped,
|
|
153
153
|
None,
|
|
154
154
|
args,
|
|
@@ -158,7 +158,7 @@ def wrap_converse(instrumentor: PayiInstrumentor, wrapped: Any) -> Any:
|
|
|
158
158
|
|
|
159
159
|
return invoke_wrapper
|
|
160
160
|
|
|
161
|
-
def wrap_converse_stream(instrumentor:
|
|
161
|
+
def wrap_converse_stream(instrumentor: _PayiInstrumentor, wrapped: Any) -> Any:
|
|
162
162
|
@wraps(wrapped)
|
|
163
163
|
def invoke_wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
164
164
|
modelId:str = kwargs.get("modelId", "") # type: ignore
|
|
@@ -169,7 +169,7 @@ def wrap_converse_stream(instrumentor: PayiInstrumentor, wrapped: Any) -> Any:
|
|
|
169
169
|
process_converse_streaming_chunk,
|
|
170
170
|
process_converse_request,
|
|
171
171
|
None,
|
|
172
|
-
|
|
172
|
+
_IsStreaming.true,
|
|
173
173
|
wrapped,
|
|
174
174
|
None,
|
|
175
175
|
args,
|
|
@@ -187,7 +187,7 @@ def process_invoke_streaming_anthropic_chunk(chunk: str, ingest: IngestUnitsPara
|
|
|
187
187
|
usage = chunk_dict['message']['usage']
|
|
188
188
|
units = ingest["units"]
|
|
189
189
|
|
|
190
|
-
input =
|
|
190
|
+
input = _PayiInstrumentor.update_for_vision(usage['input_tokens'], units)
|
|
191
191
|
|
|
192
192
|
units["text"] = Units(input=input, output=0)
|
|
193
193
|
|
|
@@ -215,7 +215,7 @@ def process_synchronous_invoke_response(
|
|
|
215
215
|
response: Any,
|
|
216
216
|
ingest: IngestUnitsParams,
|
|
217
217
|
log_prompt_and_response: bool,
|
|
218
|
-
instrumentor:
|
|
218
|
+
instrumentor: _PayiInstrumentor,
|
|
219
219
|
**kargs: Any) -> Any: # noqa: ARG001
|
|
220
220
|
|
|
221
221
|
metadata = response.get("ResponseMetadata", {})
|
payi/lib/OpenAIInstrumentor.py
CHANGED
|
@@ -9,7 +9,7 @@ from wrapt import wrap_function_wrapper # type: ignore
|
|
|
9
9
|
from payi.types import IngestUnitsParams
|
|
10
10
|
from payi.types.ingest_units_params import Units
|
|
11
11
|
|
|
12
|
-
from .instrument import
|
|
12
|
+
from .instrument import _IsStreaming, _PayiInstrumentor
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
class OpenAiInstrumentor:
|
|
@@ -20,7 +20,7 @@ class OpenAiInstrumentor:
|
|
|
20
20
|
return isinstance(instance._client, (AsyncAzureOpenAI, AzureOpenAI))
|
|
21
21
|
|
|
22
22
|
@staticmethod
|
|
23
|
-
def instrument(instrumentor:
|
|
23
|
+
def instrument(instrumentor: _PayiInstrumentor) -> None:
|
|
24
24
|
try:
|
|
25
25
|
from openai import OpenAI # type: ignore # noqa: F401 I001
|
|
26
26
|
|
|
@@ -53,9 +53,9 @@ class OpenAiInstrumentor:
|
|
|
53
53
|
return
|
|
54
54
|
|
|
55
55
|
|
|
56
|
-
@
|
|
56
|
+
@_PayiInstrumentor.payi_wrapper
|
|
57
57
|
def embeddings_wrapper(
|
|
58
|
-
instrumentor:
|
|
58
|
+
instrumentor: _PayiInstrumentor,
|
|
59
59
|
wrapped: Any,
|
|
60
60
|
instance: Any,
|
|
61
61
|
*args: Any,
|
|
@@ -66,16 +66,16 @@ def embeddings_wrapper(
|
|
|
66
66
|
None, # process_chat_chunk,
|
|
67
67
|
None, # process_chat_request,
|
|
68
68
|
process_ebmeddings_synchronous_response,
|
|
69
|
-
|
|
69
|
+
_IsStreaming.false,
|
|
70
70
|
wrapped,
|
|
71
71
|
instance,
|
|
72
72
|
args,
|
|
73
73
|
kwargs,
|
|
74
74
|
)
|
|
75
75
|
|
|
76
|
-
@
|
|
76
|
+
@_PayiInstrumentor.payi_wrapper
|
|
77
77
|
async def aembeddings_wrapper(
|
|
78
|
-
instrumentor:
|
|
78
|
+
instrumentor: _PayiInstrumentor,
|
|
79
79
|
wrapped: Any,
|
|
80
80
|
instance: Any,
|
|
81
81
|
*args: Any,
|
|
@@ -86,16 +86,16 @@ async def aembeddings_wrapper(
|
|
|
86
86
|
None, # process_chat_chunk,
|
|
87
87
|
None, # process_chat_request,
|
|
88
88
|
process_ebmeddings_synchronous_response,
|
|
89
|
-
|
|
89
|
+
_IsStreaming.false,
|
|
90
90
|
wrapped,
|
|
91
91
|
instance,
|
|
92
92
|
args,
|
|
93
93
|
kwargs,
|
|
94
94
|
)
|
|
95
95
|
|
|
96
|
-
@
|
|
96
|
+
@_PayiInstrumentor.payi_wrapper
|
|
97
97
|
def chat_wrapper(
|
|
98
|
-
instrumentor:
|
|
98
|
+
instrumentor: _PayiInstrumentor,
|
|
99
99
|
wrapped: Any,
|
|
100
100
|
instance: Any,
|
|
101
101
|
*args: Any,
|
|
@@ -106,16 +106,16 @@ def chat_wrapper(
|
|
|
106
106
|
process_chat_chunk,
|
|
107
107
|
process_chat_request,
|
|
108
108
|
process_chat_synchronous_response,
|
|
109
|
-
|
|
109
|
+
_IsStreaming.kwargs,
|
|
110
110
|
wrapped,
|
|
111
111
|
instance,
|
|
112
112
|
args,
|
|
113
113
|
kwargs,
|
|
114
114
|
)
|
|
115
115
|
|
|
116
|
-
@
|
|
116
|
+
@_PayiInstrumentor.payi_awrapper
|
|
117
117
|
async def achat_wrapper(
|
|
118
|
-
instrumentor:
|
|
118
|
+
instrumentor: _PayiInstrumentor,
|
|
119
119
|
wrapped: Any,
|
|
120
120
|
instance: Any,
|
|
121
121
|
*args: Any,
|
|
@@ -126,7 +126,7 @@ async def achat_wrapper(
|
|
|
126
126
|
process_chat_chunk,
|
|
127
127
|
process_chat_request,
|
|
128
128
|
process_chat_synchronous_response,
|
|
129
|
-
|
|
129
|
+
_IsStreaming.kwargs,
|
|
130
130
|
wrapped,
|
|
131
131
|
instance,
|
|
132
132
|
args,
|
|
@@ -184,7 +184,7 @@ def add_usage_units(usage: "dict[str, Any]", units: "dict[str, Units]") -> None:
|
|
|
184
184
|
if input_cache != 0:
|
|
185
185
|
units["text_cache_read"] = Units(input=input_cache, output=0)
|
|
186
186
|
|
|
187
|
-
input =
|
|
187
|
+
input = _PayiInstrumentor.update_for_vision(input - input_cache, units)
|
|
188
188
|
|
|
189
189
|
units["text"] = Units(input=input, output=output)
|
|
190
190
|
|
|
@@ -221,4 +221,4 @@ def process_chat_request(ingest: IngestUnitsParams, *args: Any, **kwargs: Any) -
|
|
|
221
221
|
if not has_image or estimated_token_count == 0:
|
|
222
222
|
return
|
|
223
223
|
|
|
224
|
-
ingest["units"][
|
|
224
|
+
ingest["units"][_PayiInstrumentor.estimated_prompt_tokens] = Units(input=estimated_token_count, output=0)
|
payi/lib/helpers.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import os
|
|
1
2
|
from typing import Dict, List, Union
|
|
2
3
|
|
|
3
4
|
PAYI_BASE_URL = "https://api.pay-i.com"
|
|
@@ -69,22 +70,25 @@ def create_headers(
|
|
|
69
70
|
headers.update({ PayiHeaderNames.use_case_version: str(use_case_version)})
|
|
70
71
|
return headers
|
|
71
72
|
|
|
73
|
+
def _resolve_payi_base_url(payi_base_url: Union[str, None]) -> str:
|
|
74
|
+
if payi_base_url:
|
|
75
|
+
return payi_base_url
|
|
76
|
+
|
|
77
|
+
payi_base_url = os.environ.get("PAYI_BASE_URL", None)
|
|
78
|
+
|
|
79
|
+
if payi_base_url:
|
|
80
|
+
return payi_base_url
|
|
81
|
+
|
|
82
|
+
return PAYI_BASE_URL
|
|
83
|
+
|
|
72
84
|
def payi_anthropic_url(payi_base_url: Union[str, None] = None) -> str:
|
|
73
|
-
|
|
74
|
-
payi_base_url = PAYI_BASE_URL
|
|
75
|
-
return payi_base_url + "/api/v1/proxy/anthropic"
|
|
85
|
+
return _resolve_payi_base_url(payi_base_url=payi_base_url) + "/api/v1/proxy/anthropic"
|
|
76
86
|
|
|
77
87
|
def payi_openai_url(payi_base_url: Union[str, None] = None) -> str:
|
|
78
|
-
|
|
79
|
-
payi_base_url = PAYI_BASE_URL
|
|
80
|
-
return payi_base_url + "/api/v1/proxy/openai/v1"
|
|
88
|
+
return _resolve_payi_base_url(payi_base_url=payi_base_url) + "/api/v1/proxy/openai/v1"
|
|
81
89
|
|
|
82
90
|
def payi_azure_openai_url(payi_base_url: Union[str, None] = None) -> str:
|
|
83
|
-
|
|
84
|
-
payi_base_url = PAYI_BASE_URL
|
|
85
|
-
return payi_base_url + "/api/v1/proxy/azure.openai"
|
|
91
|
+
return _resolve_payi_base_url(payi_base_url=payi_base_url) + "/api/v1/proxy/azure.openai"
|
|
86
92
|
|
|
87
93
|
def payi_aws_bedrock_url(payi_base_url: Union[str, None] = None) -> str:
|
|
88
|
-
|
|
89
|
-
payi_base_url = PAYI_BASE_URL
|
|
90
|
-
return payi_base_url + "/api/v1/proxy/aws.bedrock"
|
|
94
|
+
return _resolve_payi_base_url(payi_base_url=payi_base_url) + "/api/v1/proxy/aws.bedrock"
|