retab 0.0.42__py3-none-any.whl → 0.0.44__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/__init__.py +2 -1
- retab/client.py +26 -51
- retab/generate_types.py +180 -0
- retab/resources/consensus/client.py +1 -1
- retab/resources/consensus/responses.py +1 -1
- retab/resources/deployments/__init__.py +3 -0
- retab/resources/deployments/automations/__init__.py +9 -0
- retab/resources/deployments/automations/client.py +244 -0
- retab/resources/deployments/automations/endpoints.py +290 -0
- retab/resources/deployments/automations/links.py +303 -0
- retab/resources/deployments/automations/logs.py +222 -0
- retab/resources/deployments/automations/mailboxes.py +423 -0
- retab/resources/deployments/automations/outlook.py +377 -0
- retab/resources/deployments/automations/tests.py +161 -0
- retab/resources/deployments/client.py +148 -0
- retab/resources/documents/client.py +94 -68
- retab/resources/documents/extractions.py +55 -46
- retab/resources/evaluations/__init__.py +2 -2
- retab/resources/evaluations/client.py +61 -77
- retab/resources/evaluations/documents.py +48 -37
- retab/resources/evaluations/iterations.py +58 -40
- retab/resources/jsonlUtils.py +3 -4
- retab/resources/processors/automations/endpoints.py +49 -39
- retab/resources/processors/automations/links.py +52 -43
- retab/resources/processors/automations/mailboxes.py +74 -59
- retab/resources/processors/automations/outlook.py +104 -82
- retab/resources/processors/client.py +35 -30
- retab/resources/projects/__init__.py +3 -0
- retab/resources/projects/client.py +285 -0
- retab/resources/projects/documents.py +244 -0
- retab/resources/projects/iterations.py +470 -0
- retab/resources/usage.py +2 -0
- retab/types/ai_models.py +2 -1
- retab/types/deprecated_evals.py +195 -0
- retab/types/evaluations/__init__.py +5 -2
- retab/types/evaluations/iterations.py +9 -43
- retab/types/evaluations/model.py +19 -24
- retab/types/extractions.py +1 -0
- retab/types/jobs/base.py +1 -1
- retab/types/jobs/evaluation.py +1 -1
- retab/types/logs.py +5 -6
- retab/types/mime.py +1 -10
- retab/types/projects/__init__.py +34 -0
- retab/types/projects/documents.py +30 -0
- retab/types/projects/iterations.py +78 -0
- retab/types/projects/model.py +68 -0
- retab/types/schemas/enhance.py +22 -5
- retab/types/schemas/evaluate.py +2 -2
- retab/types/schemas/object.py +27 -25
- retab/types/standards.py +2 -2
- retab/utils/__init__.py +3 -0
- retab/utils/ai_models.py +127 -12
- retab/utils/hashing.py +24 -0
- retab/utils/json_schema.py +1 -26
- retab/utils/mime.py +0 -17
- retab/utils/usage/usage.py +0 -1
- {retab-0.0.42.dist-info → retab-0.0.44.dist-info}/METADATA +4 -6
- {retab-0.0.42.dist-info → retab-0.0.44.dist-info}/RECORD +60 -55
- retab/_utils/__init__.py +0 -0
- retab/_utils/_model_cards/anthropic.yaml +0 -59
- retab/_utils/_model_cards/auto.yaml +0 -43
- retab/_utils/_model_cards/gemini.yaml +0 -117
- retab/_utils/_model_cards/openai.yaml +0 -301
- retab/_utils/_model_cards/xai.yaml +0 -28
- retab/_utils/ai_models.py +0 -138
- retab/_utils/benchmarking.py +0 -484
- retab/_utils/chat.py +0 -327
- retab/_utils/display.py +0 -440
- retab/_utils/json_schema.py +0 -2156
- retab/_utils/mime.py +0 -165
- retab/_utils/responses.py +0 -169
- retab/_utils/stream_context_managers.py +0 -52
- retab/_utils/usage/__init__.py +0 -0
- retab/_utils/usage/usage.py +0 -301
- {retab-0.0.42.dist-info → retab-0.0.44.dist-info}/WHEEL +0 -0
- {retab-0.0.42.dist-info → retab-0.0.44.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,285 @@
|
|
1
|
+
from typing import Any, Dict, List
|
2
|
+
|
3
|
+
from ..._resource import AsyncAPIResource, SyncAPIResource
|
4
|
+
from ...types.projects import Project, PatchProjectRequest, ListProjectParams, BaseProject
|
5
|
+
from ...types.inference_settings import InferenceSettings
|
6
|
+
from ...types.standards import PreparedRequest, DeleteResponse, FieldUnset
|
7
|
+
from .documents import Documents, AsyncDocuments
|
8
|
+
from .iterations import Iterations, AsyncIterations
|
9
|
+
|
10
|
+
|
11
|
+
class ProjectsMixin:
|
12
|
+
def prepare_create(
|
13
|
+
self,
|
14
|
+
name: str,
|
15
|
+
json_schema: dict[str, Any],
|
16
|
+
default_inference_settings: InferenceSettings = FieldUnset,
|
17
|
+
) -> PreparedRequest:
|
18
|
+
# Use BaseProject model
|
19
|
+
eval_dict = {
|
20
|
+
"name": name,
|
21
|
+
"json_schema": json_schema,
|
22
|
+
}
|
23
|
+
if default_inference_settings is not FieldUnset:
|
24
|
+
eval_dict["default_inference_settings"] = default_inference_settings
|
25
|
+
|
26
|
+
eval_data = BaseProject(**eval_dict)
|
27
|
+
return PreparedRequest(method="POST", url="/v1/projects", data=eval_data.model_dump(exclude_unset=True, mode="json"))
|
28
|
+
|
29
|
+
def prepare_get(self, evaluation_id: str) -> PreparedRequest:
|
30
|
+
return PreparedRequest(method="GET", url=f"/v1/projects/{evaluation_id}")
|
31
|
+
|
32
|
+
def prepare_update(
|
33
|
+
self,
|
34
|
+
evaluation_id: str,
|
35
|
+
name: str = FieldUnset,
|
36
|
+
json_schema: dict[str, Any] = FieldUnset,
|
37
|
+
default_inference_settings: InferenceSettings = FieldUnset,
|
38
|
+
) -> PreparedRequest:
|
39
|
+
"""
|
40
|
+
Prepare a request to update an evaluation with partial updates.
|
41
|
+
|
42
|
+
Only the provided fields will be updated. Fields set to None will be excluded from the update.
|
43
|
+
"""
|
44
|
+
# Build a dictionary with only the provided fields
|
45
|
+
update_dict = {}
|
46
|
+
if name is not FieldUnset:
|
47
|
+
update_dict["name"] = name
|
48
|
+
if json_schema is not FieldUnset:
|
49
|
+
update_dict["json_schema"] = json_schema
|
50
|
+
if default_inference_settings is not FieldUnset:
|
51
|
+
update_dict["default_inference_settings"] = default_inference_settings
|
52
|
+
|
53
|
+
data = PatchProjectRequest(**update_dict).model_dump(exclude_unset=True, mode="json")
|
54
|
+
|
55
|
+
return PreparedRequest(method="PATCH", url=f"/v1/projects/{evaluation_id}", data=data)
|
56
|
+
|
57
|
+
def prepare_list(self) -> PreparedRequest:
|
58
|
+
"""
|
59
|
+
Prepare a request to list evaluations.
|
60
|
+
|
61
|
+
Usage:
|
62
|
+
>>> client.evaluations.list() # List all evaluations
|
63
|
+
|
64
|
+
Returns:
|
65
|
+
PreparedRequest: The prepared request
|
66
|
+
"""
|
67
|
+
params_dict = {}
|
68
|
+
|
69
|
+
params = ListProjectParams(**params_dict).model_dump(exclude_unset=True, exclude_defaults=True, mode="json")
|
70
|
+
return PreparedRequest(method="GET", url="/v1/projects", params=params)
|
71
|
+
|
72
|
+
def prepare_delete(self, id: str) -> PreparedRequest:
|
73
|
+
return PreparedRequest(method="DELETE", url=f"/v1/projects/{id}")
|
74
|
+
|
75
|
+
|
76
|
+
class Projects(SyncAPIResource, ProjectsMixin):
|
77
|
+
"""Projects API wrapper"""
|
78
|
+
|
79
|
+
def __init__(self, *args, **kwargs):
|
80
|
+
super().__init__(*args, **kwargs)
|
81
|
+
self.documents = Documents(self._client)
|
82
|
+
self.iterations = Iterations(self._client)
|
83
|
+
|
84
|
+
def create(
|
85
|
+
self,
|
86
|
+
name: str,
|
87
|
+
json_schema: dict[str, Any],
|
88
|
+
default_inference_settings: InferenceSettings = FieldUnset,
|
89
|
+
) -> Project:
|
90
|
+
"""
|
91
|
+
Create a new evaluation.
|
92
|
+
|
93
|
+
Args:
|
94
|
+
name: The name of the evaluation
|
95
|
+
json_schema: The JSON schema for the evaluation
|
96
|
+
documents: The documents to associate with the evaluation
|
97
|
+
default_inference_settings: The default inference settings to associate with the evaluation
|
98
|
+
|
99
|
+
Returns:
|
100
|
+
Project: The created evaluation
|
101
|
+
Raises:
|
102
|
+
HTTPException if the request fails
|
103
|
+
"""
|
104
|
+
request = self.prepare_create(name, json_schema, default_inference_settings=default_inference_settings)
|
105
|
+
response = self._client._prepared_request(request)
|
106
|
+
return Project(**response)
|
107
|
+
|
108
|
+
def get(self, evaluation_id: str) -> Project:
|
109
|
+
"""
|
110
|
+
Get an evaluation by ID.
|
111
|
+
|
112
|
+
Args:
|
113
|
+
evaluation_id: The ID of the evaluation to retrieve
|
114
|
+
|
115
|
+
Returns:
|
116
|
+
Project: The evaluation
|
117
|
+
Raises:
|
118
|
+
HTTPException if the request fails
|
119
|
+
"""
|
120
|
+
request = self.prepare_get(evaluation_id)
|
121
|
+
response = self._client._prepared_request(request)
|
122
|
+
return Project(**response)
|
123
|
+
|
124
|
+
def update(
|
125
|
+
self,
|
126
|
+
evaluation_id: str,
|
127
|
+
name: str = FieldUnset,
|
128
|
+
json_schema: dict[str, Any] = FieldUnset,
|
129
|
+
default_inference_settings: InferenceSettings = FieldUnset,
|
130
|
+
) -> Project:
|
131
|
+
"""
|
132
|
+
Update an evaluation with partial updates.
|
133
|
+
|
134
|
+
Args:
|
135
|
+
evaluation_id: The ID of the evaluation to update
|
136
|
+
name: Optional new name for the evaluation
|
137
|
+
json_schema: Optional new JSON schema
|
138
|
+
documents: Optional list of documents to update
|
139
|
+
iterations: Optional list of iterations to update
|
140
|
+
default_inference_settings: Optional annotation properties
|
141
|
+
|
142
|
+
Returns:
|
143
|
+
Project: The updated evaluation
|
144
|
+
Raises:
|
145
|
+
HTTPException if the request fails
|
146
|
+
"""
|
147
|
+
request = self.prepare_update(
|
148
|
+
evaluation_id=evaluation_id,
|
149
|
+
name=name,
|
150
|
+
json_schema=json_schema,
|
151
|
+
default_inference_settings=default_inference_settings,
|
152
|
+
)
|
153
|
+
response = self._client._prepared_request(request)
|
154
|
+
return Project(**response)
|
155
|
+
|
156
|
+
def list(self) -> List[Project]:
|
157
|
+
"""
|
158
|
+
List evaluations for a project.
|
159
|
+
|
160
|
+
Args:
|
161
|
+
Returns:
|
162
|
+
List[Project]: List of evaluations
|
163
|
+
Raises:
|
164
|
+
HTTPException if the request fails
|
165
|
+
"""
|
166
|
+
request = self.prepare_list()
|
167
|
+
response = self._client._prepared_request(request)
|
168
|
+
return [Project(**item) for item in response.get("data", [])]
|
169
|
+
|
170
|
+
def delete(self, evaluation_id: str) -> DeleteResponse:
|
171
|
+
"""
|
172
|
+
Delete an evaluation.
|
173
|
+
|
174
|
+
Args:
|
175
|
+
evaluation_id: The ID of the evaluation to delete
|
176
|
+
|
177
|
+
Returns:
|
178
|
+
DeleteResponse: The response containing success status and ID
|
179
|
+
Raises:
|
180
|
+
HTTPException if the request fails
|
181
|
+
"""
|
182
|
+
request = self.prepare_delete(evaluation_id)
|
183
|
+
return self._client._prepared_request(request)
|
184
|
+
|
185
|
+
|
186
|
+
class AsyncProjects(AsyncAPIResource, ProjectsMixin):
|
187
|
+
"""Async Projects API wrapper"""
|
188
|
+
|
189
|
+
def __init__(self, *args, **kwargs):
|
190
|
+
super().__init__(*args, **kwargs)
|
191
|
+
self.documents = AsyncDocuments(self._client)
|
192
|
+
self.iterations = AsyncIterations(self._client)
|
193
|
+
|
194
|
+
async def create(self, name: str, json_schema: Dict[str, Any]) -> Project:
|
195
|
+
"""
|
196
|
+
Create a new evaluation.
|
197
|
+
|
198
|
+
Args:
|
199
|
+
name: The name of the evaluation
|
200
|
+
json_schema: The JSON schema for the evaluation
|
201
|
+
|
202
|
+
Returns:
|
203
|
+
Project: The created evaluation
|
204
|
+
Raises:
|
205
|
+
HTTPException if the request fails
|
206
|
+
"""
|
207
|
+
request = self.prepare_create(name, json_schema)
|
208
|
+
response = await self._client._prepared_request(request)
|
209
|
+
return Project(**response)
|
210
|
+
|
211
|
+
async def get(self, evaluation_id: str) -> Project:
|
212
|
+
"""
|
213
|
+
Get an evaluation by ID.
|
214
|
+
|
215
|
+
Args:
|
216
|
+
evaluation_id: The ID of the evaluation to retrieve
|
217
|
+
|
218
|
+
Returns:
|
219
|
+
Project: The evaluation
|
220
|
+
Raises:
|
221
|
+
HTTPException if the request fails
|
222
|
+
"""
|
223
|
+
request = self.prepare_get(evaluation_id)
|
224
|
+
response = await self._client._prepared_request(request)
|
225
|
+
return Project(**response)
|
226
|
+
|
227
|
+
async def update(
|
228
|
+
self,
|
229
|
+
evaluation_id: str,
|
230
|
+
name: str = FieldUnset,
|
231
|
+
json_schema: dict[str, Any] = FieldUnset,
|
232
|
+
default_inference_settings: InferenceSettings = FieldUnset,
|
233
|
+
) -> Project:
|
234
|
+
"""
|
235
|
+
Update an evaluation with partial updates.
|
236
|
+
|
237
|
+
Args:
|
238
|
+
id: The ID of the evaluation to update
|
239
|
+
name: Optional new name for the evaluation
|
240
|
+
json_schema: Optional new JSON schema
|
241
|
+
documents: Optional list of documents to update
|
242
|
+
iterations: Optional list of iterations to update
|
243
|
+
default_inference_settings: Optional annotation properties
|
244
|
+
|
245
|
+
Returns:
|
246
|
+
Project: The updated evaluation
|
247
|
+
Raises:
|
248
|
+
HTTPException if the request fails
|
249
|
+
"""
|
250
|
+
request = self.prepare_update(
|
251
|
+
evaluation_id=evaluation_id,
|
252
|
+
name=name,
|
253
|
+
json_schema=json_schema,
|
254
|
+
default_inference_settings=default_inference_settings,
|
255
|
+
)
|
256
|
+
response = await self._client._prepared_request(request)
|
257
|
+
return Project(**response)
|
258
|
+
|
259
|
+
async def list(self) -> List[Project]:
|
260
|
+
"""
|
261
|
+
List evaluations for a project.
|
262
|
+
|
263
|
+
Returns:
|
264
|
+
List[Project]: List of evaluations
|
265
|
+
Raises:
|
266
|
+
HTTPException if the request fails
|
267
|
+
"""
|
268
|
+
request = self.prepare_list()
|
269
|
+
response = await self._client._prepared_request(request)
|
270
|
+
return [Project(**item) for item in response.get("data", [])]
|
271
|
+
|
272
|
+
async def delete(self, evaluation_id: str) -> DeleteResponse:
|
273
|
+
"""
|
274
|
+
Delete an evaluation.
|
275
|
+
|
276
|
+
Args:
|
277
|
+
evaluation_id: The ID of the evaluation to delete
|
278
|
+
|
279
|
+
Returns:
|
280
|
+
DeleteResponse: The response containing success status and ID
|
281
|
+
Raises:
|
282
|
+
HTTPException if the request fails
|
283
|
+
"""
|
284
|
+
request = self.prepare_delete(evaluation_id)
|
285
|
+
return await self._client._prepared_request(request)
|
@@ -0,0 +1,244 @@
|
|
1
|
+
from io import IOBase
|
2
|
+
from pathlib import Path
|
3
|
+
from typing import Any, Dict, List, Union
|
4
|
+
|
5
|
+
import PIL.Image
|
6
|
+
from pydantic import HttpUrl
|
7
|
+
|
8
|
+
from ..._resource import AsyncAPIResource, SyncAPIResource
|
9
|
+
from ...utils.mime import prepare_mime_document
|
10
|
+
from ...types.projects import DocumentItem, ProjectDocument, PatchProjectDocumentRequest
|
11
|
+
from ...types.predictions import PredictionMetadata
|
12
|
+
from ...types.mime import MIMEData
|
13
|
+
from ...types.standards import PreparedRequest, DeleteResponse, FieldUnset
|
14
|
+
from ...types.documents.extractions import RetabParsedChatCompletion
|
15
|
+
|
16
|
+
|
17
|
+
class DocumentsMixin:
|
18
|
+
def prepare_get(self, evaluation_id: str, document_id: str) -> PreparedRequest:
|
19
|
+
return PreparedRequest(method="GET", url=f"/v1/projects/{evaluation_id}/documents/{document_id}")
|
20
|
+
|
21
|
+
def prepare_create(self, evaluation_id: str, document: MIMEData, annotation: dict[str, Any], annotation_metadata: dict[str, Any] | None = None) -> PreparedRequest:
|
22
|
+
# Serialize the MIMEData
|
23
|
+
document_item = DocumentItem(mime_data=document, annotation=annotation, annotation_metadata=PredictionMetadata(**annotation_metadata) if annotation_metadata else None)
|
24
|
+
return PreparedRequest(method="POST", url=f"/v1/projects/{evaluation_id}/documents", data=document_item.model_dump(mode="json"))
|
25
|
+
|
26
|
+
def prepare_list(self, evaluation_id: str) -> PreparedRequest:
|
27
|
+
return PreparedRequest(method="GET", url=f"/v1/projects/{evaluation_id}/documents")
|
28
|
+
|
29
|
+
def prepare_update(self, evaluation_id: str, document_id: str, annotation: dict[str, Any]) -> PreparedRequest:
|
30
|
+
update_request = PatchProjectDocumentRequest(annotation=annotation)
|
31
|
+
return PreparedRequest(method="PATCH", url=f"/v1/projects/{evaluation_id}/documents/{document_id}", data=update_request.model_dump(mode="json", exclude_unset=True))
|
32
|
+
|
33
|
+
def prepare_delete(self, evaluation_id: str, document_id: str) -> PreparedRequest:
|
34
|
+
return PreparedRequest(method="DELETE", url=f"/v1/projects/{evaluation_id}/documents/{document_id}")
|
35
|
+
|
36
|
+
def prepare_llm_annotate(self, evaluation_id: str, document_id: str) -> PreparedRequest:
|
37
|
+
return PreparedRequest(method="POST", url=f"/v1/projects/{evaluation_id}/documents/{document_id}/llm-annotate", data={"stream": False})
|
38
|
+
|
39
|
+
|
40
|
+
class Documents(SyncAPIResource, DocumentsMixin):
|
41
|
+
"""Documents API wrapper for evaluations"""
|
42
|
+
|
43
|
+
def create(
|
44
|
+
self,
|
45
|
+
evaluation_id: str,
|
46
|
+
document: Union[Path, str, IOBase, MIMEData, PIL.Image.Image, HttpUrl],
|
47
|
+
annotation: Dict[str, Any],
|
48
|
+
annotation_metadata: Dict[str, Any] | None = None,
|
49
|
+
) -> ProjectDocument:
|
50
|
+
"""
|
51
|
+
Create a document for an evaluation.
|
52
|
+
|
53
|
+
Args:
|
54
|
+
evaluation_id: The ID of the evaluation
|
55
|
+
document: The document to process. Can be:
|
56
|
+
- A file path (Path or str)
|
57
|
+
- A file-like object (IOBase)
|
58
|
+
- A MIMEData object
|
59
|
+
- A PIL Image object
|
60
|
+
- A URL (HttpUrl)
|
61
|
+
annotation: The ground truth for the document
|
62
|
+
|
63
|
+
Returns:
|
64
|
+
ProjectDocument: The created document
|
65
|
+
Raises:
|
66
|
+
HTTPException if the request fails
|
67
|
+
"""
|
68
|
+
# Convert document to MIME data format
|
69
|
+
mime_document: MIMEData = prepare_mime_document(document)
|
70
|
+
|
71
|
+
# Let prepare_create handle the serialization
|
72
|
+
request = self.prepare_create(evaluation_id, mime_document, annotation, annotation_metadata)
|
73
|
+
response = self._client._prepared_request(request)
|
74
|
+
return ProjectDocument(**response)
|
75
|
+
|
76
|
+
def list(self, evaluation_id: str) -> List[ProjectDocument]:
|
77
|
+
"""
|
78
|
+
List documents for an evaluation.
|
79
|
+
|
80
|
+
Args:
|
81
|
+
evaluation_id: The ID of the evaluation
|
82
|
+
|
83
|
+
Returns:
|
84
|
+
List[ProjectDocument]: List of documents
|
85
|
+
Raises:
|
86
|
+
HTTPException if the request fails
|
87
|
+
"""
|
88
|
+
request = self.prepare_list(evaluation_id)
|
89
|
+
response = self._client._prepared_request(request)
|
90
|
+
return [ProjectDocument(**item) for item in response.get("data", [])]
|
91
|
+
|
92
|
+
def get(self, evaluation_id: str, document_id: str) -> ProjectDocument:
|
93
|
+
"""
|
94
|
+
Get a document by ID.
|
95
|
+
|
96
|
+
Args:
|
97
|
+
evaluation_id: The ID of the evaluation
|
98
|
+
document_id: The ID of the document
|
99
|
+
|
100
|
+
Returns:
|
101
|
+
ProjectDocument: The document
|
102
|
+
Raises:
|
103
|
+
HTTPException if the request fails
|
104
|
+
"""
|
105
|
+
request = self.prepare_get(evaluation_id, document_id)
|
106
|
+
response = self._client._prepared_request(request)
|
107
|
+
return ProjectDocument(**response)
|
108
|
+
|
109
|
+
def update(self, evaluation_id: str, document_id: str, annotation: dict[str, Any]) -> ProjectDocument:
|
110
|
+
"""
|
111
|
+
Update a document.
|
112
|
+
|
113
|
+
Args:
|
114
|
+
evaluation_id: The ID of the evaluation
|
115
|
+
document_id: The ID of the document
|
116
|
+
annotation: The ground truth for the document
|
117
|
+
Returns:
|
118
|
+
ProjectDocument: The updated document
|
119
|
+
Raises:
|
120
|
+
HTTPException if the request fails
|
121
|
+
"""
|
122
|
+
request = self.prepare_update(evaluation_id, document_id, annotation=annotation)
|
123
|
+
response = self._client._prepared_request(request)
|
124
|
+
return ProjectDocument(**response)
|
125
|
+
|
126
|
+
def delete(self, evaluation_id: str, document_id: str) -> DeleteResponse:
|
127
|
+
"""
|
128
|
+
Delete a document.
|
129
|
+
|
130
|
+
Args:
|
131
|
+
evaluation_id: The ID of the evaluation
|
132
|
+
document_id: The ID of the document
|
133
|
+
|
134
|
+
Returns:
|
135
|
+
DeleteResponse: The response containing success status and ID
|
136
|
+
Raises:
|
137
|
+
HTTPException if the request fails
|
138
|
+
"""
|
139
|
+
request = self.prepare_delete(evaluation_id, document_id)
|
140
|
+
return self._client._prepared_request(request)
|
141
|
+
|
142
|
+
def llm_annotate(self, evaluation_id: str, document_id: str) -> RetabParsedChatCompletion:
|
143
|
+
"""
|
144
|
+
Annotate a document with an LLM. This method updates the document (within the evaluation) with the latest extraction.
|
145
|
+
"""
|
146
|
+
request = self.prepare_llm_annotate(evaluation_id, document_id)
|
147
|
+
response = self._client._prepared_request(request)
|
148
|
+
return RetabParsedChatCompletion(**response)
|
149
|
+
|
150
|
+
|
151
|
+
class AsyncDocuments(AsyncAPIResource, DocumentsMixin):
|
152
|
+
"""Async Documents API wrapper for evaluations"""
|
153
|
+
|
154
|
+
async def create(
|
155
|
+
self,
|
156
|
+
evaluation_id: str,
|
157
|
+
document: Union[Path, str, IOBase, MIMEData, PIL.Image.Image, HttpUrl],
|
158
|
+
annotation: Dict[str, Any],
|
159
|
+
annotation_metadata: Dict[str, Any] | None = None,
|
160
|
+
) -> ProjectDocument:
|
161
|
+
"""
|
162
|
+
Create a document for an evaluation.
|
163
|
+
|
164
|
+
Args:
|
165
|
+
evaluation_id: The ID of the evaluation
|
166
|
+
document: The document to process. Can be:
|
167
|
+
- A file path (Path or str)
|
168
|
+
- A file-like object (IOBase)
|
169
|
+
- A MIMEData object
|
170
|
+
- A PIL Image object
|
171
|
+
- A URL (HttpUrl)
|
172
|
+
annotation: The ground truth for the document
|
173
|
+
annotation_metadata: The metadata of the annotation
|
174
|
+
Returns:
|
175
|
+
ProjectDocument: The created document
|
176
|
+
Raises:
|
177
|
+
HTTPException if the request fails
|
178
|
+
"""
|
179
|
+
# Convert document to MIME data format
|
180
|
+
mime_document: MIMEData = prepare_mime_document(document)
|
181
|
+
|
182
|
+
# Let prepare_create handle the serialization
|
183
|
+
request = self.prepare_create(evaluation_id, mime_document, annotation, annotation_metadata)
|
184
|
+
response = await self._client._prepared_request(request)
|
185
|
+
return ProjectDocument(**response)
|
186
|
+
|
187
|
+
async def list(self, evaluation_id: str) -> List[ProjectDocument]:
|
188
|
+
"""
|
189
|
+
List documents for an evaluation.
|
190
|
+
|
191
|
+
Args:
|
192
|
+
evaluation_id: The ID of the evaluation
|
193
|
+
|
194
|
+
Returns:
|
195
|
+
List[ProjectDocument]: List of documents
|
196
|
+
Raises:
|
197
|
+
HTTPException if the request fails
|
198
|
+
"""
|
199
|
+
request = self.prepare_list(evaluation_id)
|
200
|
+
response = await self._client._prepared_request(request)
|
201
|
+
return [ProjectDocument(**item) for item in response.get("data", [])]
|
202
|
+
|
203
|
+
async def update(self, evaluation_id: str, document_id: str, annotation: dict[str, Any]) -> ProjectDocument:
|
204
|
+
"""
|
205
|
+
Update a document.
|
206
|
+
|
207
|
+
Args:
|
208
|
+
evaluation_id: The ID of the evaluation
|
209
|
+
document_id: The ID of the document
|
210
|
+
annotation: The ground truth for the document
|
211
|
+
|
212
|
+
Returns:
|
213
|
+
ProjectDocument: The updated document
|
214
|
+
Raises:
|
215
|
+
HTTPException if the request fails
|
216
|
+
"""
|
217
|
+
request = self.prepare_update(evaluation_id, document_id, annotation)
|
218
|
+
response = await self._client._prepared_request(request)
|
219
|
+
return ProjectDocument(**response)
|
220
|
+
|
221
|
+
async def delete(self, evaluation_id: str, document_id: str) -> DeleteResponse:
|
222
|
+
"""
|
223
|
+
Delete a document.
|
224
|
+
|
225
|
+
Args:
|
226
|
+
evaluation_id: The ID of the evaluation
|
227
|
+
document_id: The ID of the document
|
228
|
+
|
229
|
+
Returns:
|
230
|
+
DeleteResponse: The response containing success status and ID
|
231
|
+
Raises:
|
232
|
+
HTTPException if the request fails
|
233
|
+
"""
|
234
|
+
request = self.prepare_delete(evaluation_id, document_id)
|
235
|
+
return await self._client._prepared_request(request)
|
236
|
+
|
237
|
+
async def llm_annotate(self, evaluation_id: str, document_id: str) -> RetabParsedChatCompletion:
|
238
|
+
"""
|
239
|
+
Annotate a document with an LLM.
|
240
|
+
This method updates the document (within the evaluation) with the latest extraction.
|
241
|
+
"""
|
242
|
+
request = self.prepare_llm_annotate(evaluation_id, document_id)
|
243
|
+
response = await self._client._prepared_request(request)
|
244
|
+
return RetabParsedChatCompletion(**response)
|