retab 0.0.35__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.
- retab-0.0.35.dist-info/METADATA +417 -0
- retab-0.0.35.dist-info/RECORD +111 -0
- retab-0.0.35.dist-info/WHEEL +5 -0
- retab-0.0.35.dist-info/top_level.txt +1 -0
- uiform/__init__.py +4 -0
- uiform/_resource.py +28 -0
- uiform/_utils/__init__.py +0 -0
- uiform/_utils/ai_models.py +100 -0
- uiform/_utils/benchmarking copy.py +588 -0
- uiform/_utils/benchmarking.py +485 -0
- uiform/_utils/chat.py +332 -0
- uiform/_utils/display.py +443 -0
- uiform/_utils/json_schema.py +2161 -0
- uiform/_utils/mime.py +168 -0
- uiform/_utils/responses.py +163 -0
- uiform/_utils/stream_context_managers.py +52 -0
- uiform/_utils/usage/__init__.py +0 -0
- uiform/_utils/usage/usage.py +300 -0
- uiform/client.py +701 -0
- uiform/py.typed +0 -0
- uiform/resources/__init__.py +0 -0
- uiform/resources/consensus/__init__.py +3 -0
- uiform/resources/consensus/client.py +114 -0
- uiform/resources/consensus/completions.py +252 -0
- uiform/resources/consensus/completions_stream.py +278 -0
- uiform/resources/consensus/responses.py +325 -0
- uiform/resources/consensus/responses_stream.py +373 -0
- uiform/resources/deployments/__init__.py +9 -0
- uiform/resources/deployments/client.py +78 -0
- uiform/resources/deployments/endpoints.py +322 -0
- uiform/resources/deployments/links.py +452 -0
- uiform/resources/deployments/logs.py +211 -0
- uiform/resources/deployments/mailboxes.py +496 -0
- uiform/resources/deployments/outlook.py +531 -0
- uiform/resources/deployments/tests.py +158 -0
- uiform/resources/documents/__init__.py +3 -0
- uiform/resources/documents/client.py +255 -0
- uiform/resources/documents/extractions.py +441 -0
- uiform/resources/evals.py +812 -0
- uiform/resources/files.py +24 -0
- uiform/resources/finetuning.py +62 -0
- uiform/resources/jsonlUtils.py +1046 -0
- uiform/resources/models.py +45 -0
- uiform/resources/openai_example.py +22 -0
- uiform/resources/processors/__init__.py +3 -0
- uiform/resources/processors/automations/__init__.py +9 -0
- uiform/resources/processors/automations/client.py +78 -0
- uiform/resources/processors/automations/endpoints.py +317 -0
- uiform/resources/processors/automations/links.py +356 -0
- uiform/resources/processors/automations/logs.py +211 -0
- uiform/resources/processors/automations/mailboxes.py +435 -0
- uiform/resources/processors/automations/outlook.py +444 -0
- uiform/resources/processors/automations/tests.py +158 -0
- uiform/resources/processors/client.py +474 -0
- uiform/resources/prompt_optimization.py +76 -0
- uiform/resources/schemas.py +369 -0
- uiform/resources/secrets/__init__.py +9 -0
- uiform/resources/secrets/client.py +20 -0
- uiform/resources/secrets/external_api_keys.py +109 -0
- uiform/resources/secrets/webhook.py +62 -0
- uiform/resources/usage.py +271 -0
- uiform/types/__init__.py +0 -0
- uiform/types/ai_models.py +645 -0
- uiform/types/automations/__init__.py +0 -0
- uiform/types/automations/cron.py +58 -0
- uiform/types/automations/endpoints.py +21 -0
- uiform/types/automations/links.py +28 -0
- uiform/types/automations/mailboxes.py +60 -0
- uiform/types/automations/outlook.py +68 -0
- uiform/types/automations/webhooks.py +21 -0
- uiform/types/chat.py +8 -0
- uiform/types/completions.py +93 -0
- uiform/types/consensus.py +10 -0
- uiform/types/db/__init__.py +0 -0
- uiform/types/db/annotations.py +24 -0
- uiform/types/db/files.py +36 -0
- uiform/types/deployments/__init__.py +0 -0
- uiform/types/deployments/cron.py +59 -0
- uiform/types/deployments/endpoints.py +28 -0
- uiform/types/deployments/links.py +36 -0
- uiform/types/deployments/mailboxes.py +67 -0
- uiform/types/deployments/outlook.py +76 -0
- uiform/types/deployments/webhooks.py +21 -0
- uiform/types/documents/__init__.py +0 -0
- uiform/types/documents/correct_orientation.py +13 -0
- uiform/types/documents/create_messages.py +226 -0
- uiform/types/documents/extractions.py +297 -0
- uiform/types/evals.py +207 -0
- uiform/types/events.py +76 -0
- uiform/types/extractions.py +85 -0
- uiform/types/jobs/__init__.py +0 -0
- uiform/types/jobs/base.py +150 -0
- uiform/types/jobs/batch_annotation.py +22 -0
- uiform/types/jobs/evaluation.py +133 -0
- uiform/types/jobs/finetune.py +6 -0
- uiform/types/jobs/prompt_optimization.py +41 -0
- uiform/types/jobs/webcrawl.py +6 -0
- uiform/types/logs.py +231 -0
- uiform/types/mime.py +257 -0
- uiform/types/modalities.py +68 -0
- uiform/types/pagination.py +6 -0
- uiform/types/schemas/__init__.py +0 -0
- uiform/types/schemas/enhance.py +53 -0
- uiform/types/schemas/evaluate.py +55 -0
- uiform/types/schemas/generate.py +32 -0
- uiform/types/schemas/layout.py +58 -0
- uiform/types/schemas/object.py +631 -0
- uiform/types/schemas/templates.py +107 -0
- uiform/types/secrets/__init__.py +0 -0
- uiform/types/secrets/external_api_keys.py +22 -0
- uiform/types/standards.py +39 -0
@@ -0,0 +1,271 @@
|
|
1
|
+
import datetime
|
2
|
+
from typing import Optional
|
3
|
+
|
4
|
+
from openai.types.chat import completion_create_params
|
5
|
+
from openai.types.chat.chat_completion import ChatCompletion
|
6
|
+
from pydantic import BaseModel
|
7
|
+
|
8
|
+
from .._resource import AsyncAPIResource, SyncAPIResource
|
9
|
+
from ..types.ai_models import Amount
|
10
|
+
from ..types.logs import AutomationLog, LogCompletionRequest
|
11
|
+
from ..types.standards import PreparedRequest
|
12
|
+
|
13
|
+
total_cost = 0.0
|
14
|
+
|
15
|
+
|
16
|
+
class UsageMixin:
|
17
|
+
def prepare_total(self, start_date: Optional[datetime.datetime] = None, end_date: Optional[datetime.datetime] = None) -> PreparedRequest:
|
18
|
+
raise NotImplementedError("prepare_total is not implemented")
|
19
|
+
|
20
|
+
def prepare_mailbox(self, email: str, start_date: Optional[datetime.datetime] = None, end_date: Optional[datetime.datetime] = None) -> PreparedRequest:
|
21
|
+
params = {}
|
22
|
+
if start_date:
|
23
|
+
params["start_date"] = start_date.isoformat()
|
24
|
+
if end_date:
|
25
|
+
params["end_date"] = end_date.isoformat()
|
26
|
+
|
27
|
+
return PreparedRequest(method="GET", url=f"/v1/processors/automations/mailboxes/{email}/usage", params=params)
|
28
|
+
|
29
|
+
def prepare_link(self, link_id: str, start_date: Optional[datetime.datetime] = None, end_date: Optional[datetime.datetime] = None) -> PreparedRequest:
|
30
|
+
params = {}
|
31
|
+
if start_date:
|
32
|
+
params["start_date"] = start_date.isoformat()
|
33
|
+
if end_date:
|
34
|
+
params["end_date"] = end_date.isoformat()
|
35
|
+
|
36
|
+
return PreparedRequest(method="GET", url=f"/v1/processors/automations/links/{link_id}/usage", params=params)
|
37
|
+
|
38
|
+
def prepare_schema(self, schema_id: str, start_date: Optional[datetime.datetime] = None, end_date: Optional[datetime.datetime] = None) -> PreparedRequest:
|
39
|
+
params = {}
|
40
|
+
if start_date:
|
41
|
+
params["start_date"] = start_date.isoformat()
|
42
|
+
if end_date:
|
43
|
+
params["end_date"] = end_date.isoformat()
|
44
|
+
|
45
|
+
return PreparedRequest(method="GET", url=f"/v1/schemas/{schema_id}/usage", params=params)
|
46
|
+
|
47
|
+
def prepare_schema_data(self, schema_data_id: str, start_date: Optional[datetime.datetime] = None, end_date: Optional[datetime.datetime] = None) -> PreparedRequest:
|
48
|
+
params = {}
|
49
|
+
if start_date:
|
50
|
+
params["start_date"] = start_date.isoformat()
|
51
|
+
if end_date:
|
52
|
+
params["end_date"] = end_date.isoformat()
|
53
|
+
|
54
|
+
return PreparedRequest(method="GET", url=f"/v1/schemas/{schema_data_id}/usage_data", params=params)
|
55
|
+
|
56
|
+
def prepare_log(self, response_format: completion_create_params.ResponseFormat, completion: ChatCompletion) -> PreparedRequest:
|
57
|
+
if isinstance(response_format, BaseModel):
|
58
|
+
log_completion_request = LogCompletionRequest(json_schema=response_format.model_json_schema(), completion=completion)
|
59
|
+
elif isinstance(response_format, dict):
|
60
|
+
if "json_schema" in response_format:
|
61
|
+
json_schema = response_format["json_schema"] # type: ignore
|
62
|
+
if "schema" in json_schema:
|
63
|
+
log_completion_request = LogCompletionRequest(json_schema=json_schema["schema"], completion=completion)
|
64
|
+
else:
|
65
|
+
raise ValueError("Invalid response format")
|
66
|
+
else:
|
67
|
+
raise ValueError("Invalid response format")
|
68
|
+
else:
|
69
|
+
raise ValueError("Invalid response format")
|
70
|
+
|
71
|
+
return PreparedRequest(method="POST", url="/v1/usage/log", data=log_completion_request.model_dump())
|
72
|
+
|
73
|
+
|
74
|
+
class Usage(SyncAPIResource, UsageMixin):
|
75
|
+
def total(self, start_date: Optional[datetime.datetime] = None, end_date: Optional[datetime.datetime] = None) -> Amount:
|
76
|
+
"""Get the total usage cost for a mailbox within an optional date range.
|
77
|
+
|
78
|
+
Returns:
|
79
|
+
Amount: The total usage cost
|
80
|
+
"""
|
81
|
+
return Amount(value=total_cost, currency="USD")
|
82
|
+
|
83
|
+
def mailbox(self, email: str, start_date: Optional[datetime.datetime] = None, end_date: Optional[datetime.datetime] = None) -> Amount:
|
84
|
+
"""Get the total usage cost for a mailbox within an optional date range.
|
85
|
+
|
86
|
+
Args:
|
87
|
+
email: The email address of the mailbox
|
88
|
+
start_date: Start date for usage calculation
|
89
|
+
end_date: End date for usage calculation
|
90
|
+
|
91
|
+
Returns:
|
92
|
+
Amount: The total usage cost
|
93
|
+
"""
|
94
|
+
request = self.prepare_mailbox(email, start_date, end_date)
|
95
|
+
response = self._client._request(request.method, request.url, request.data, request.params)
|
96
|
+
return Amount.model_validate(response)
|
97
|
+
|
98
|
+
def link(self, link_id: str, start_date: Optional[datetime.datetime] = None, end_date: Optional[datetime.datetime] = None) -> Amount:
|
99
|
+
"""Get the total usage cost for a link within an optional date range.
|
100
|
+
|
101
|
+
Args:
|
102
|
+
link_id: The ID of the link
|
103
|
+
start_date: Start date for usage calculation
|
104
|
+
end_date: End date for usage calculation
|
105
|
+
|
106
|
+
Returns:
|
107
|
+
Amount: The total usage cost
|
108
|
+
"""
|
109
|
+
request = self.prepare_link(link_id, start_date, end_date)
|
110
|
+
response = self._client._request(request.method, request.url, request.data, request.params)
|
111
|
+
return Amount.model_validate(response)
|
112
|
+
|
113
|
+
def schema(self, schema_id: str, start_date: Optional[datetime.datetime] = None, end_date: Optional[datetime.datetime] = None) -> Amount:
|
114
|
+
"""Get the total usage cost for a schema within an optional date range.
|
115
|
+
|
116
|
+
Args:
|
117
|
+
schema_id: The ID of the schema
|
118
|
+
start_date: Start date for usage calculation
|
119
|
+
end_date: End date for usage calculation
|
120
|
+
|
121
|
+
Returns:
|
122
|
+
Amount: The total usage cost
|
123
|
+
"""
|
124
|
+
request = self.prepare_schema(schema_id, start_date, end_date)
|
125
|
+
response = self._client._request(request.method, request.url, request.data, request.params)
|
126
|
+
return Amount.model_validate(response)
|
127
|
+
|
128
|
+
def schema_data(self, schema_data_id: str, start_date: Optional[datetime.datetime] = None, end_date: Optional[datetime.datetime] = None) -> Amount:
|
129
|
+
"""Get the total usage cost for a schema within an optional date range.
|
130
|
+
|
131
|
+
Args:
|
132
|
+
schema_id: The ID of the schema
|
133
|
+
start_date: Start date for usage calculation
|
134
|
+
end_date: End date for usage calculation
|
135
|
+
|
136
|
+
Returns:
|
137
|
+
Amount: The total usage cost
|
138
|
+
"""
|
139
|
+
request = self.prepare_schema_data(schema_data_id, start_date, end_date)
|
140
|
+
response = self._client._request(request.method, request.url, request.data, request.params)
|
141
|
+
return Amount.model_validate(response)
|
142
|
+
|
143
|
+
# TODO: Turn that into an async process
|
144
|
+
def log(self, response_format: completion_create_params.ResponseFormat, completion: ChatCompletion) -> AutomationLog:
|
145
|
+
"""Logs an openai request completion as an automation log to make the usage calculation possible for the user
|
146
|
+
|
147
|
+
client = OpenAI()
|
148
|
+
completion = client.beta.chat.completions.parse(
|
149
|
+
model="gpt-4o-2024-08-06",
|
150
|
+
messages=[
|
151
|
+
{"role": "developer", "content": "Extract the event information."},
|
152
|
+
{"role": "user", "content": "Alice and Bob are going to a science fair on Friday."},
|
153
|
+
],
|
154
|
+
response_format=CalendarEvent,
|
155
|
+
)
|
156
|
+
uiclient.usage.log(
|
157
|
+
response_format=CalendarEvent,
|
158
|
+
completion=completion
|
159
|
+
)
|
160
|
+
|
161
|
+
|
162
|
+
Args:
|
163
|
+
response_format: The response format of the openai request
|
164
|
+
completion: The completion of the openai request
|
165
|
+
|
166
|
+
Returns:
|
167
|
+
AutomationLog: The automation log
|
168
|
+
"""
|
169
|
+
request = self.prepare_log(response_format, completion)
|
170
|
+
response = self._client._request(request.method, request.url, request.data, request.params)
|
171
|
+
return AutomationLog.model_validate(response)
|
172
|
+
|
173
|
+
|
174
|
+
class AsyncUsage(AsyncAPIResource, UsageMixin):
|
175
|
+
async def total(self, start_date: Optional[datetime.datetime] = None, end_date: Optional[datetime.datetime] = None) -> Amount:
|
176
|
+
"""Get the total usage cost for a mailbox within an optional date range.
|
177
|
+
|
178
|
+
Returns:
|
179
|
+
Amount: The total usage cost
|
180
|
+
"""
|
181
|
+
return Amount(value=total_cost, currency="USD")
|
182
|
+
|
183
|
+
async def mailbox(self, email: str, start_date: Optional[datetime.datetime] = None, end_date: Optional[datetime.datetime] = None) -> Amount:
|
184
|
+
"""Get the total usage cost for a mailbox within an optional date range.
|
185
|
+
|
186
|
+
Args:
|
187
|
+
email: The email address of the mailbox
|
188
|
+
start_date: Start date for usage calculation
|
189
|
+
end_date: End date for usage calculation
|
190
|
+
|
191
|
+
Returns:
|
192
|
+
Amount: The total usage cost
|
193
|
+
"""
|
194
|
+
request = self.prepare_mailbox(email, start_date, end_date)
|
195
|
+
response = await self._client._request(request.method, request.url, request.data, request.params)
|
196
|
+
return Amount.model_validate(response)
|
197
|
+
|
198
|
+
async def link(self, link_id: str, start_date: Optional[datetime.datetime] = None, end_date: Optional[datetime.datetime] = None) -> Amount:
|
199
|
+
"""Get the total usage cost for a link within an optional date range.
|
200
|
+
|
201
|
+
Args:
|
202
|
+
link_id: The ID of the link
|
203
|
+
start_date: Start date for usage calculation
|
204
|
+
end_date: End date for usage calculation
|
205
|
+
|
206
|
+
Returns:
|
207
|
+
Amount: The total usage cost
|
208
|
+
"""
|
209
|
+
request = self.prepare_link(link_id, start_date, end_date)
|
210
|
+
response = await self._client._request(request.method, request.url, request.data, request.params)
|
211
|
+
return Amount.model_validate(response)
|
212
|
+
|
213
|
+
async def schema(self, schema_id: str, start_date: Optional[datetime.datetime] = None, end_date: Optional[datetime.datetime] = None) -> Amount:
|
214
|
+
"""Get the total usage cost for a schema within an optional date range.
|
215
|
+
|
216
|
+
Args:
|
217
|
+
schema_id: The ID of the schema
|
218
|
+
start_date: Start date for usage calculation
|
219
|
+
end_date: End date for usage calculation
|
220
|
+
|
221
|
+
Returns:
|
222
|
+
Amount: The total usage cost
|
223
|
+
"""
|
224
|
+
request = self.prepare_schema(schema_id, start_date, end_date)
|
225
|
+
response = await self._client._request(request.method, request.url, request.data, request.params)
|
226
|
+
return Amount.model_validate(response)
|
227
|
+
|
228
|
+
async def schema_data(self, schema_data_id: str, start_date: Optional[datetime.datetime] = None, end_date: Optional[datetime.datetime] = None) -> Amount:
|
229
|
+
"""Get the total usage cost for a schema within an optional date range.
|
230
|
+
|
231
|
+
Args:
|
232
|
+
schema_id: The ID of the schema
|
233
|
+
start_date: Start date for usage calculation
|
234
|
+
end_date: End date for usage calculation
|
235
|
+
|
236
|
+
Returns:
|
237
|
+
Amount: The total usage cost
|
238
|
+
"""
|
239
|
+
request = self.prepare_schema_data(schema_data_id, start_date, end_date)
|
240
|
+
response = await self._client._request(request.method, request.url, request.data, request.params)
|
241
|
+
return Amount.model_validate(response)
|
242
|
+
|
243
|
+
# TODO: Turn that into an async process
|
244
|
+
async def log(self, response_format: completion_create_params.ResponseFormat, completion: ChatCompletion) -> AutomationLog:
|
245
|
+
"""Logs an openai request completion as an automation log to make the usage calculation possible for the user
|
246
|
+
|
247
|
+
client = OpenAI()
|
248
|
+
completion = client.beta.chat.completions.parse(
|
249
|
+
model="gpt-4o-2024-08-06",
|
250
|
+
messages=[
|
251
|
+
{"role": "developer", "content": "Extract the event information."},
|
252
|
+
{"role": "user", "content": "Alice and Bob are going to a science fair on Friday."},
|
253
|
+
],
|
254
|
+
response_format=CalendarEvent,
|
255
|
+
)
|
256
|
+
uiclient.usage.log(
|
257
|
+
response_format=CalendarEvent,
|
258
|
+
completion=completion
|
259
|
+
)
|
260
|
+
|
261
|
+
|
262
|
+
Args:
|
263
|
+
response_format: The response format of the openai request
|
264
|
+
completion: The completion of the openai request
|
265
|
+
|
266
|
+
Returns:
|
267
|
+
AutomationLog: The automation log
|
268
|
+
"""
|
269
|
+
request = self.prepare_log(response_format, completion)
|
270
|
+
response = await self._client._request(request.method, request.url, request.data, request.params)
|
271
|
+
return AutomationLog.model_validate(response)
|
uiform/types/__init__.py
ADDED
File without changes
|