uipath 2.1.118__py3-none-any.whl → 2.1.119__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 uipath might be problematic. Click here for more details.
- uipath/_resources/SDK_REFERENCE.md +9 -3
- uipath/_services/documents_service.py +466 -59
- uipath/models/documents.py +64 -0
- {uipath-2.1.118.dist-info → uipath-2.1.119.dist-info}/METADATA +1 -1
- {uipath-2.1.118.dist-info → uipath-2.1.119.dist-info}/RECORD +8 -8
- {uipath-2.1.118.dist-info → uipath-2.1.119.dist-info}/WHEEL +0 -0
- {uipath-2.1.118.dist-info → uipath-2.1.119.dist-info}/entry_points.txt +0 -0
- {uipath-2.1.118.dist-info → uipath-2.1.119.dist-info}/licenses/LICENSE +0 -0
|
@@ -124,17 +124,23 @@ sdk.context_grounding.search_async(name: str, query: str, number_of_results: int
|
|
|
124
124
|
Documents service
|
|
125
125
|
|
|
126
126
|
```python
|
|
127
|
+
# Classify a document using a DU Modern project.
|
|
128
|
+
sdk.documents.classify(tag: str, project_name: str, file: Union[IO[bytes], bytes, str, NoneType]=None, file_path: Optional[str]=None) -> typing.List[uipath.models.documents.ClassificationResult]
|
|
129
|
+
|
|
130
|
+
# Asynchronously version of the [`classify`][uipath._services.documents_service.DocumentsService.classify] method.
|
|
131
|
+
sdk.documents.classify_async(tag: str, project_name: str, file: Union[IO[bytes], bytes, str, NoneType]=None, file_path: Optional[str]=None) -> typing.List[uipath.models.documents.ClassificationResult]
|
|
132
|
+
|
|
127
133
|
# Create a validation action for a document based on the extraction response. More details about validation actions can be found in the [official documentation](https://docs.uipath.com/ixp/automation-cloud/latest/user-guide/validating-extractions).
|
|
128
134
|
sdk.documents.create_validation_action(action_title: str, action_priority: <enum 'ActionPriority, action_catalog: str, action_folder: str, storage_bucket_name: str, storage_bucket_directory_path: str, extraction_response: uipath.models.documents.ExtractionResponse) -> uipath.models.documents.ValidationAction
|
|
129
135
|
|
|
130
136
|
# Asynchronous version of the [`create_validation_action`][uipath._services.documents_service.DocumentsService.create_validation_action] method.
|
|
131
137
|
sdk.documents.create_validation_action_async(action_title: str, action_priority: <enum 'ActionPriority, action_catalog: str, action_folder: str, storage_bucket_name: str, storage_bucket_directory_path: str, extraction_response: uipath.models.documents.ExtractionResponse) -> uipath.models.documents.ValidationAction
|
|
132
138
|
|
|
133
|
-
# Extract predicted data from a document using an IXP project.
|
|
134
|
-
sdk.documents.extract(
|
|
139
|
+
# Extract predicted data from a document using an DU Modern/IXP project.
|
|
140
|
+
sdk.documents.extract(tag: str, project_name: Optional[str]=None, file: Union[IO[bytes], bytes, str, NoneType]=None, file_path: Optional[str]=None, classification_result: Optional[uipath.models.documents.ClassificationResult]=None, project_type: Optional[uipath.models.documents.ProjectType]=None, document_type_name: Optional[str]=None) -> typing.Union[uipath.models.documents.ExtractionResponse, uipath.models.documents.ExtractionResponseIXP]
|
|
135
141
|
|
|
136
142
|
# Asynchronously version of the [`extract`][uipath._services.documents_service.DocumentsService.extract] method.
|
|
137
|
-
sdk.documents.extract_async(
|
|
143
|
+
sdk.documents.extract_async(tag: str, project_name: Optional[str]=None, file: Union[IO[bytes], bytes, str, NoneType]=None, file_path: Optional[str]=None, classification_result: Optional[uipath.models.documents.ClassificationResult]=None, project_type: Optional[uipath.models.documents.ProjectType]=None, document_type_name: Optional[str]=None) -> typing.Union[uipath.models.documents.ExtractionResponse, uipath.models.documents.ExtractionResponseIXP]
|
|
138
144
|
|
|
139
145
|
# Get the result of a validation action.
|
|
140
146
|
sdk.documents.get_validation_result(validation_action: uipath.models.documents.ValidationAction) -> uipath.models.documents.ValidatedResult
|
|
@@ -13,6 +13,8 @@ from .._folder_context import FolderContext
|
|
|
13
13
|
from .._utils import Endpoint
|
|
14
14
|
from ..models.documents import (
|
|
15
15
|
ActionPriority,
|
|
16
|
+
ClassificationResponse,
|
|
17
|
+
ClassificationResult,
|
|
16
18
|
ExtractionResponse,
|
|
17
19
|
ExtractionResponseIXP,
|
|
18
20
|
ProjectType,
|
|
@@ -26,6 +28,58 @@ POLLING_INTERVAL = 2 # seconds
|
|
|
26
28
|
POLLING_TIMEOUT = 300 # seconds
|
|
27
29
|
|
|
28
30
|
|
|
31
|
+
def _is_provided(arg: Any) -> bool:
|
|
32
|
+
return arg is not None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _must_not_be_provided(**kwargs: Any) -> None:
|
|
36
|
+
for name, value in kwargs.items():
|
|
37
|
+
if value is not None:
|
|
38
|
+
raise ValueError(f"`{name}` must not be provided")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _must_be_provided(**kwargs: Any) -> None:
|
|
42
|
+
for name, value in kwargs.items():
|
|
43
|
+
if value is None:
|
|
44
|
+
raise ValueError(f"`{name}` must be provided")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _exactly_one_must_be_provided(**kwargs: Any) -> None:
|
|
48
|
+
provided = [name for name, value in kwargs.items() if value is not None]
|
|
49
|
+
if len(provided) != 1:
|
|
50
|
+
raise ValueError(
|
|
51
|
+
f"Exactly one of `{', '.join(kwargs.keys())}` must be provided"
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _validate_extract_params_and_get_project_type(
|
|
56
|
+
project_name: Optional[str],
|
|
57
|
+
file: Optional[FileContent],
|
|
58
|
+
file_path: Optional[str],
|
|
59
|
+
classification_result: Optional[ClassificationResult],
|
|
60
|
+
project_type: Optional[ProjectType],
|
|
61
|
+
document_type_name: Optional[str],
|
|
62
|
+
) -> ProjectType:
|
|
63
|
+
if _is_provided(project_name):
|
|
64
|
+
_must_be_provided(project_type=project_type)
|
|
65
|
+
_exactly_one_must_be_provided(file=file, file_path=file_path)
|
|
66
|
+
_must_not_be_provided(classification_result=classification_result)
|
|
67
|
+
if project_type == ProjectType.MODERN:
|
|
68
|
+
_must_be_provided(document_type_name=document_type_name)
|
|
69
|
+
else:
|
|
70
|
+
_must_not_be_provided(
|
|
71
|
+
project_name=project_name,
|
|
72
|
+
project_type=project_type,
|
|
73
|
+
file=file,
|
|
74
|
+
file_path=file_path,
|
|
75
|
+
document_type_name=document_type_name,
|
|
76
|
+
)
|
|
77
|
+
_must_be_provided(classification_result=classification_result)
|
|
78
|
+
project_type = ProjectType.MODERN
|
|
79
|
+
|
|
80
|
+
return project_type # type: ignore
|
|
81
|
+
|
|
82
|
+
|
|
29
83
|
class DocumentsService(FolderContext, BaseService):
|
|
30
84
|
"""Service for managing UiPath DocumentUnderstanding Document Operations.
|
|
31
85
|
|
|
@@ -100,10 +154,65 @@ class DocumentsService(FolderContext, BaseService):
|
|
|
100
154
|
)
|
|
101
155
|
return {tag["name"] for tag in response.json().get("tags", [])}
|
|
102
156
|
|
|
157
|
+
def _get_document_id(
|
|
158
|
+
self,
|
|
159
|
+
project_id: Optional[str],
|
|
160
|
+
file: Optional[FileContent],
|
|
161
|
+
file_path: Optional[str],
|
|
162
|
+
classification_result: Optional[ClassificationResult],
|
|
163
|
+
) -> str:
|
|
164
|
+
if classification_result is not None:
|
|
165
|
+
return classification_result.document_id
|
|
166
|
+
|
|
167
|
+
document_id = self._start_digitization(
|
|
168
|
+
project_id=project_id, # type: ignore
|
|
169
|
+
file=file,
|
|
170
|
+
file_path=file_path,
|
|
171
|
+
)
|
|
172
|
+
self._wait_for_digitization(
|
|
173
|
+
project_id=project_id, # type: ignore
|
|
174
|
+
document_id=document_id,
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
return document_id
|
|
178
|
+
|
|
179
|
+
async def _get_document_id_async(
|
|
180
|
+
self,
|
|
181
|
+
project_id: Optional[str],
|
|
182
|
+
file: Optional[FileContent],
|
|
183
|
+
file_path: Optional[str],
|
|
184
|
+
classification_result: Optional[ClassificationResult],
|
|
185
|
+
) -> str:
|
|
186
|
+
if classification_result is not None:
|
|
187
|
+
return classification_result.document_id
|
|
188
|
+
|
|
189
|
+
document_id = await self._start_digitization_async(
|
|
190
|
+
project_id=project_id, # type: ignore
|
|
191
|
+
file=file,
|
|
192
|
+
file_path=file_path,
|
|
193
|
+
)
|
|
194
|
+
await self._wait_for_digitization_async(
|
|
195
|
+
project_id=project_id, # type: ignore
|
|
196
|
+
document_id=document_id,
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
return document_id
|
|
200
|
+
|
|
103
201
|
def _get_project_id_and_validate_tag(
|
|
104
|
-
self,
|
|
202
|
+
self,
|
|
203
|
+
tag: str,
|
|
204
|
+
project_name: Optional[str],
|
|
205
|
+
project_type: Optional[ProjectType],
|
|
206
|
+
classification_result: Optional[ClassificationResult],
|
|
105
207
|
) -> str:
|
|
106
|
-
|
|
208
|
+
if project_name is not None:
|
|
209
|
+
project_id = self._get_project_id_by_name(
|
|
210
|
+
project_name,
|
|
211
|
+
project_type, # type: ignore
|
|
212
|
+
)
|
|
213
|
+
else:
|
|
214
|
+
project_id = classification_result.project_id # type: ignore
|
|
215
|
+
|
|
107
216
|
tags = self._get_project_tags(project_id)
|
|
108
217
|
if tag not in tags:
|
|
109
218
|
raise ValueError(
|
|
@@ -113,11 +222,20 @@ class DocumentsService(FolderContext, BaseService):
|
|
|
113
222
|
return project_id
|
|
114
223
|
|
|
115
224
|
async def _get_project_id_and_validate_tag_async(
|
|
116
|
-
self,
|
|
225
|
+
self,
|
|
226
|
+
tag: str,
|
|
227
|
+
project_name: Optional[str],
|
|
228
|
+
project_type: Optional[ProjectType],
|
|
229
|
+
classification_result: Optional[ClassificationResult],
|
|
117
230
|
) -> str:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
231
|
+
if project_name is not None:
|
|
232
|
+
project_id = await self._get_project_id_by_name_async(
|
|
233
|
+
project_name,
|
|
234
|
+
project_type, # type: ignore
|
|
235
|
+
)
|
|
236
|
+
else:
|
|
237
|
+
project_id = classification_result.project_id # type: ignore
|
|
238
|
+
|
|
121
239
|
tags = await self._get_project_tags_async(project_id)
|
|
122
240
|
if tag not in tags:
|
|
123
241
|
raise ValueError(
|
|
@@ -129,44 +247,100 @@ class DocumentsService(FolderContext, BaseService):
|
|
|
129
247
|
def _start_digitization(
|
|
130
248
|
self,
|
|
131
249
|
project_id: str,
|
|
132
|
-
file: FileContent,
|
|
250
|
+
file: Optional[FileContent] = None,
|
|
251
|
+
file_path: Optional[str] = None,
|
|
133
252
|
) -> str:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
253
|
+
with open(Path(file_path), "rb") if file_path else nullcontext(file) as handle:
|
|
254
|
+
return self.request(
|
|
255
|
+
"POST",
|
|
256
|
+
url=Endpoint(
|
|
257
|
+
f"/du_/api/framework/projects/{project_id}/digitization/start"
|
|
258
|
+
),
|
|
259
|
+
params={"api-version": 1.1},
|
|
260
|
+
headers=self._get_common_headers(),
|
|
261
|
+
files={"File": handle},
|
|
262
|
+
).json()["documentId"]
|
|
143
263
|
|
|
144
264
|
async def _start_digitization_async(
|
|
145
265
|
self,
|
|
146
266
|
project_id: str,
|
|
147
|
-
file: FileContent,
|
|
267
|
+
file: Optional[FileContent] = None,
|
|
268
|
+
file_path: Optional[str] = None,
|
|
148
269
|
) -> str:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
270
|
+
with open(Path(file_path), "rb") if file_path else nullcontext(file) as handle:
|
|
271
|
+
return (
|
|
272
|
+
await self.request_async(
|
|
273
|
+
"POST",
|
|
274
|
+
url=Endpoint(
|
|
275
|
+
f"/du_/api/framework/projects/{project_id}/digitization/start"
|
|
276
|
+
),
|
|
277
|
+
params={"api-version": 1.1},
|
|
278
|
+
headers=self._get_common_headers(),
|
|
279
|
+
files={"File": handle},
|
|
280
|
+
)
|
|
281
|
+
).json()["documentId"]
|
|
282
|
+
|
|
283
|
+
def _wait_for_digitization(self, project_id: str, document_id: str) -> None:
|
|
284
|
+
def result_getter() -> Tuple[str, Optional[str], Optional[str]]:
|
|
285
|
+
result = self.request(
|
|
286
|
+
method="GET",
|
|
152
287
|
url=Endpoint(
|
|
153
|
-
f"/du_/api/framework/projects/{project_id}/digitization/
|
|
288
|
+
f"/du_/api/framework/projects/{project_id}/digitization/result/{document_id}"
|
|
154
289
|
),
|
|
155
290
|
params={"api-version": 1.1},
|
|
156
291
|
headers=self._get_common_headers(),
|
|
157
|
-
|
|
292
|
+
).json()
|
|
293
|
+
return (
|
|
294
|
+
result["status"],
|
|
295
|
+
result.get("error", None),
|
|
296
|
+
result.get("result", None),
|
|
158
297
|
)
|
|
159
|
-
|
|
298
|
+
|
|
299
|
+
self._wait_for_operation(
|
|
300
|
+
result_getter=result_getter,
|
|
301
|
+
wait_statuses=["NotStarted", "Running"],
|
|
302
|
+
success_status="Succeeded",
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
async def _wait_for_digitization_async(
|
|
306
|
+
self, project_id: str, document_id: str
|
|
307
|
+
) -> None:
|
|
308
|
+
async def result_getter() -> Tuple[str, Optional[str], Optional[str]]:
|
|
309
|
+
result = (
|
|
310
|
+
await self.request_async(
|
|
311
|
+
method="GET",
|
|
312
|
+
url=Endpoint(
|
|
313
|
+
f"/du_/api/framework/projects/{project_id}/digitization/result/{document_id}"
|
|
314
|
+
),
|
|
315
|
+
params={"api-version": 1.1},
|
|
316
|
+
headers=self._get_common_headers(),
|
|
317
|
+
)
|
|
318
|
+
).json()
|
|
319
|
+
return (
|
|
320
|
+
result["status"],
|
|
321
|
+
result.get("error", None),
|
|
322
|
+
result.get("result", None),
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
await self._wait_for_operation_async(
|
|
326
|
+
result_getter=result_getter,
|
|
327
|
+
wait_statuses=["NotStarted", "Running"],
|
|
328
|
+
success_status="Succeeded",
|
|
329
|
+
)
|
|
160
330
|
|
|
161
331
|
def _get_document_type_id(
|
|
162
332
|
self,
|
|
163
333
|
project_id: str,
|
|
164
334
|
document_type_name: Optional[str],
|
|
165
335
|
project_type: ProjectType,
|
|
336
|
+
classification_result: Optional[ClassificationResult],
|
|
166
337
|
) -> str:
|
|
167
338
|
if project_type == ProjectType.IXP:
|
|
168
339
|
return str(UUID(int=0))
|
|
169
340
|
|
|
341
|
+
if classification_result is not None:
|
|
342
|
+
return classification_result.document_type_id
|
|
343
|
+
|
|
170
344
|
response = self.request(
|
|
171
345
|
"GET",
|
|
172
346
|
url=Endpoint(f"/du_/api/framework/projects/{project_id}/document-types"),
|
|
@@ -190,10 +364,14 @@ class DocumentsService(FolderContext, BaseService):
|
|
|
190
364
|
project_id: str,
|
|
191
365
|
document_type_name: Optional[str],
|
|
192
366
|
project_type: ProjectType,
|
|
367
|
+
classification_result: Optional[ClassificationResult],
|
|
193
368
|
) -> str:
|
|
194
369
|
if project_type == ProjectType.IXP:
|
|
195
370
|
return str(UUID(int=0))
|
|
196
371
|
|
|
372
|
+
if classification_result is not None:
|
|
373
|
+
return classification_result.document_type_id
|
|
374
|
+
|
|
197
375
|
response = await self.request_async(
|
|
198
376
|
"GET",
|
|
199
377
|
url=Endpoint(f"/du_/api/framework/projects/{project_id}/document-types"),
|
|
@@ -380,25 +558,225 @@ class DocumentsService(FolderContext, BaseService):
|
|
|
380
558
|
|
|
381
559
|
return ExtractionResponse.model_validate(extraction_response)
|
|
382
560
|
|
|
561
|
+
def _start_classification(
|
|
562
|
+
self,
|
|
563
|
+
project_id: str,
|
|
564
|
+
tag: str,
|
|
565
|
+
document_id: str,
|
|
566
|
+
) -> str:
|
|
567
|
+
return self.request(
|
|
568
|
+
"POST",
|
|
569
|
+
url=Endpoint(
|
|
570
|
+
f"/du_/api/framework/projects/{project_id}/{tag}/classification/start"
|
|
571
|
+
),
|
|
572
|
+
params={"api-version": 1.1},
|
|
573
|
+
headers=self._get_common_headers(),
|
|
574
|
+
json={"documentId": document_id},
|
|
575
|
+
).json()["operationId"]
|
|
576
|
+
|
|
577
|
+
async def _start_classification_async(
|
|
578
|
+
self,
|
|
579
|
+
project_id: str,
|
|
580
|
+
tag: str,
|
|
581
|
+
document_id: str,
|
|
582
|
+
) -> str:
|
|
583
|
+
return (
|
|
584
|
+
await self.request_async(
|
|
585
|
+
"POST",
|
|
586
|
+
url=Endpoint(
|
|
587
|
+
f"/du_/api/framework/projects/{project_id}/{tag}/classification/start"
|
|
588
|
+
),
|
|
589
|
+
params={"api-version": 1.1},
|
|
590
|
+
headers=self._get_common_headers(),
|
|
591
|
+
json={"documentId": document_id},
|
|
592
|
+
)
|
|
593
|
+
).json()["operationId"]
|
|
594
|
+
|
|
595
|
+
def _wait_for_classification(
|
|
596
|
+
self,
|
|
597
|
+
project_id: str,
|
|
598
|
+
tag: str,
|
|
599
|
+
operation_id: str,
|
|
600
|
+
) -> List[ClassificationResult]:
|
|
601
|
+
def result_getter() -> Tuple[str, Optional[str], Optional[str]]:
|
|
602
|
+
result = self.request(
|
|
603
|
+
method="GET",
|
|
604
|
+
url=Endpoint(
|
|
605
|
+
f"/du_/api/framework/projects/{project_id}/{tag}/classification/result/{operation_id}"
|
|
606
|
+
),
|
|
607
|
+
params={"api-version": 1.1},
|
|
608
|
+
headers=self._get_common_headers(),
|
|
609
|
+
).json()
|
|
610
|
+
return (
|
|
611
|
+
result["status"],
|
|
612
|
+
result.get("error", None),
|
|
613
|
+
result.get("result", None),
|
|
614
|
+
)
|
|
615
|
+
|
|
616
|
+
classification_response = self._wait_for_operation(
|
|
617
|
+
result_getter=result_getter,
|
|
618
|
+
wait_statuses=["NotStarted", "Running"],
|
|
619
|
+
success_status="Succeeded",
|
|
620
|
+
)
|
|
621
|
+
for classification_result in classification_response["classificationResults"]:
|
|
622
|
+
classification_result["ProjectId"] = project_id
|
|
623
|
+
|
|
624
|
+
return ClassificationResponse.model_validate(
|
|
625
|
+
classification_response
|
|
626
|
+
).classification_results
|
|
627
|
+
|
|
628
|
+
async def _wait_for_classification_async(
|
|
629
|
+
self,
|
|
630
|
+
project_id: str,
|
|
631
|
+
tag: str,
|
|
632
|
+
operation_id: str,
|
|
633
|
+
) -> List[ClassificationResult]:
|
|
634
|
+
async def result_getter() -> Tuple[str, Optional[str], Optional[str]]:
|
|
635
|
+
result = (
|
|
636
|
+
await self.request_async(
|
|
637
|
+
method="GET",
|
|
638
|
+
url=Endpoint(
|
|
639
|
+
f"/du_/api/framework/projects/{project_id}/{tag}/classification/result/{operation_id}"
|
|
640
|
+
),
|
|
641
|
+
params={"api-version": 1.1},
|
|
642
|
+
headers=self._get_common_headers(),
|
|
643
|
+
)
|
|
644
|
+
).json()
|
|
645
|
+
return (
|
|
646
|
+
result["status"],
|
|
647
|
+
result.get("error", None),
|
|
648
|
+
result.get("result", None),
|
|
649
|
+
)
|
|
650
|
+
|
|
651
|
+
classification_response = await self._wait_for_operation_async(
|
|
652
|
+
result_getter=result_getter,
|
|
653
|
+
wait_statuses=["NotStarted", "Running"],
|
|
654
|
+
success_status="Succeeded",
|
|
655
|
+
)
|
|
656
|
+
for classification_result in classification_response["classificationResults"]:
|
|
657
|
+
classification_result["ProjectId"] = project_id
|
|
658
|
+
|
|
659
|
+
return ClassificationResponse.model_validate(
|
|
660
|
+
classification_response
|
|
661
|
+
).classification_results
|
|
662
|
+
|
|
663
|
+
@traced(name="documents_classify", run_type="uipath")
|
|
664
|
+
def classify(
|
|
665
|
+
self,
|
|
666
|
+
tag: str,
|
|
667
|
+
project_name: str,
|
|
668
|
+
file: Optional[FileContent] = None,
|
|
669
|
+
file_path: Optional[str] = None,
|
|
670
|
+
) -> List[ClassificationResult]:
|
|
671
|
+
"""Classify a document using a DU Modern project.
|
|
672
|
+
|
|
673
|
+
Args:
|
|
674
|
+
project_name (str): Name of the [DU Modern](https://docs.uipath.com/document-understanding/automation-cloud/latest/user-guide/about-document-understanding) project.
|
|
675
|
+
tag (str): Tag of the published project version.
|
|
676
|
+
file (FileContent, optional): The document file to be classified.
|
|
677
|
+
file_path (str, optional): Path to the document file to be classified.
|
|
678
|
+
|
|
679
|
+
Note:
|
|
680
|
+
Either `file` or `file_path` must be provided, but not both.
|
|
681
|
+
|
|
682
|
+
Returns:
|
|
683
|
+
List[ClassificationResult]: A list of classification results.
|
|
684
|
+
|
|
685
|
+
Examples:
|
|
686
|
+
```python
|
|
687
|
+
with open("path/to/document.pdf", "rb") as file:
|
|
688
|
+
classification_results = service.classify(
|
|
689
|
+
project_name="MyModernProjectName",
|
|
690
|
+
tag="Production",
|
|
691
|
+
file=file,
|
|
692
|
+
)
|
|
693
|
+
```
|
|
694
|
+
"""
|
|
695
|
+
_exactly_one_must_be_provided(file=file, file_path=file_path)
|
|
696
|
+
|
|
697
|
+
project_id = self._get_project_id_and_validate_tag(
|
|
698
|
+
tag=tag,
|
|
699
|
+
project_name=project_name,
|
|
700
|
+
project_type=ProjectType.MODERN,
|
|
701
|
+
classification_result=None,
|
|
702
|
+
)
|
|
703
|
+
|
|
704
|
+
document_id = self._get_document_id(
|
|
705
|
+
project_id=project_id,
|
|
706
|
+
file=file,
|
|
707
|
+
file_path=file_path,
|
|
708
|
+
classification_result=None,
|
|
709
|
+
)
|
|
710
|
+
|
|
711
|
+
operation_id = self._start_classification(
|
|
712
|
+
project_id=project_id,
|
|
713
|
+
tag=tag,
|
|
714
|
+
document_id=document_id,
|
|
715
|
+
)
|
|
716
|
+
|
|
717
|
+
return self._wait_for_classification(
|
|
718
|
+
project_id=project_id,
|
|
719
|
+
tag=tag,
|
|
720
|
+
operation_id=operation_id,
|
|
721
|
+
)
|
|
722
|
+
|
|
723
|
+
@traced(name="documents_classify_async", run_type="uipath")
|
|
724
|
+
async def classify_async(
|
|
725
|
+
self,
|
|
726
|
+
tag: str,
|
|
727
|
+
project_name: str,
|
|
728
|
+
file: Optional[FileContent] = None,
|
|
729
|
+
file_path: Optional[str] = None,
|
|
730
|
+
) -> List[ClassificationResult]:
|
|
731
|
+
"""Asynchronously version of the [`classify`][uipath._services.documents_service.DocumentsService.classify] method."""
|
|
732
|
+
_exactly_one_must_be_provided(file=file, file_path=file_path)
|
|
733
|
+
|
|
734
|
+
project_id = await self._get_project_id_and_validate_tag_async(
|
|
735
|
+
tag=tag,
|
|
736
|
+
project_name=project_name,
|
|
737
|
+
project_type=ProjectType.MODERN,
|
|
738
|
+
classification_result=None,
|
|
739
|
+
)
|
|
740
|
+
|
|
741
|
+
document_id = await self._get_document_id_async(
|
|
742
|
+
project_id=project_id,
|
|
743
|
+
file=file,
|
|
744
|
+
file_path=file_path,
|
|
745
|
+
classification_result=None,
|
|
746
|
+
)
|
|
747
|
+
|
|
748
|
+
operation_id = await self._start_classification_async(
|
|
749
|
+
project_id=project_id,
|
|
750
|
+
tag=tag,
|
|
751
|
+
document_id=document_id,
|
|
752
|
+
)
|
|
753
|
+
|
|
754
|
+
return await self._wait_for_classification_async(
|
|
755
|
+
project_id=project_id,
|
|
756
|
+
tag=tag,
|
|
757
|
+
operation_id=operation_id,
|
|
758
|
+
)
|
|
759
|
+
|
|
383
760
|
@traced(name="documents_extract", run_type="uipath")
|
|
384
761
|
def extract(
|
|
385
762
|
self,
|
|
386
|
-
project_name: str,
|
|
387
763
|
tag: str,
|
|
764
|
+
project_name: Optional[str] = None,
|
|
388
765
|
file: Optional[FileContent] = None,
|
|
389
766
|
file_path: Optional[str] = None,
|
|
390
|
-
|
|
767
|
+
classification_result: Optional[ClassificationResult] = None,
|
|
768
|
+
project_type: Optional[ProjectType] = None,
|
|
391
769
|
document_type_name: Optional[str] = None,
|
|
392
770
|
) -> Union[ExtractionResponse, ExtractionResponseIXP]:
|
|
393
|
-
"""Extract predicted data from a document using an IXP project.
|
|
771
|
+
"""Extract predicted data from a document using an DU Modern/IXP project.
|
|
394
772
|
|
|
395
773
|
Args:
|
|
396
|
-
project_name (str): Name of the [IXP](https://docs.uipath.com/ixp/automation-cloud/latest/overview/managing-projects#creating-a-new-project)/[DU Modern](https://docs.uipath.com/document-understanding/automation-cloud/latest/user-guide/about-document-understanding) project.
|
|
774
|
+
project_name (str, optional): Name of the [IXP](https://docs.uipath.com/ixp/automation-cloud/latest/overview/managing-projects#creating-a-new-project)/[DU Modern](https://docs.uipath.com/document-understanding/automation-cloud/latest/user-guide/about-document-understanding) project. Must be provided if `classification_result` is not provided.
|
|
397
775
|
tag (str): Tag of the published project version.
|
|
398
|
-
file (FileContent, optional): The document file to be processed.
|
|
399
|
-
file_path (str, optional): Path to the document file to be processed.
|
|
400
|
-
project_type (ProjectType, optional): Type of the project.
|
|
401
|
-
document_type_name (str, optional): Document type name associated with the extractor to be used for extraction. Required if `project_type` is `ProjectType.MODERN
|
|
776
|
+
file (FileContent, optional): The document file to be processed. Must be provided if `classification_result` is not provided.
|
|
777
|
+
file_path (str, optional): Path to the document file to be processed. Must be provided if `classification_result` is not provided.
|
|
778
|
+
project_type (ProjectType, optional): Type of the project. Must be provided if `project_name` is provided.
|
|
779
|
+
document_type_name (str, optional): Document type name associated with the extractor to be used for extraction. Required if `project_type` is `ProjectType.MODERN` and `project_name` is provided.
|
|
402
780
|
|
|
403
781
|
Note:
|
|
404
782
|
Either `file` or `file_path` must be provided, but not both.
|
|
@@ -417,7 +795,7 @@ class DocumentsService(FolderContext, BaseService):
|
|
|
417
795
|
)
|
|
418
796
|
```
|
|
419
797
|
|
|
420
|
-
DU Modern projects:
|
|
798
|
+
DU Modern projects (providing document type name):
|
|
421
799
|
```python
|
|
422
800
|
with open("path/to/document.pdf", "rb") as file:
|
|
423
801
|
extraction_response = service.extract(
|
|
@@ -428,27 +806,50 @@ class DocumentsService(FolderContext, BaseService):
|
|
|
428
806
|
document_type_name="Receipts",
|
|
429
807
|
)
|
|
430
808
|
```
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
809
|
+
|
|
810
|
+
DU Modern projects (using existing classification result):
|
|
811
|
+
```python
|
|
812
|
+
with open("path/to/document.pdf", "rb") as file:
|
|
813
|
+
classification_results = uipath.documents.classify(
|
|
814
|
+
tag="Production",
|
|
815
|
+
project_name="MyModernProjectName",
|
|
816
|
+
file=file,
|
|
817
|
+
)
|
|
818
|
+
|
|
819
|
+
extraction_result = uipath.documents.extract(
|
|
820
|
+
tag="Production",
|
|
821
|
+
classification_result=max(classification_results, key=lambda result: result.confidence),
|
|
439
822
|
)
|
|
823
|
+
```
|
|
824
|
+
"""
|
|
825
|
+
project_type = _validate_extract_params_and_get_project_type(
|
|
826
|
+
project_name=project_name,
|
|
827
|
+
file=file,
|
|
828
|
+
file_path=file_path,
|
|
829
|
+
classification_result=classification_result,
|
|
830
|
+
project_type=project_type,
|
|
831
|
+
document_type_name=document_type_name,
|
|
832
|
+
)
|
|
440
833
|
|
|
441
834
|
project_id = self._get_project_id_and_validate_tag(
|
|
442
|
-
|
|
835
|
+
tag=tag,
|
|
836
|
+
project_name=project_name,
|
|
837
|
+
project_type=project_type,
|
|
838
|
+
classification_result=classification_result,
|
|
443
839
|
)
|
|
444
840
|
|
|
445
|
-
|
|
446
|
-
|
|
841
|
+
document_id = self._get_document_id(
|
|
842
|
+
project_id=project_id,
|
|
843
|
+
file=file,
|
|
844
|
+
file_path=file_path,
|
|
845
|
+
classification_result=classification_result,
|
|
846
|
+
)
|
|
447
847
|
|
|
448
848
|
document_type_id = self._get_document_type_id(
|
|
449
849
|
project_id=project_id,
|
|
450
850
|
document_type_name=document_type_name,
|
|
451
851
|
project_type=project_type,
|
|
852
|
+
classification_result=classification_result,
|
|
452
853
|
)
|
|
453
854
|
|
|
454
855
|
operation_id = self._start_extraction(
|
|
@@ -469,37 +870,43 @@ class DocumentsService(FolderContext, BaseService):
|
|
|
469
870
|
@traced(name="documents_extract_async", run_type="uipath")
|
|
470
871
|
async def extract_async(
|
|
471
872
|
self,
|
|
472
|
-
project_name: str,
|
|
473
873
|
tag: str,
|
|
874
|
+
project_name: Optional[str] = None,
|
|
474
875
|
file: Optional[FileContent] = None,
|
|
475
876
|
file_path: Optional[str] = None,
|
|
476
|
-
|
|
877
|
+
classification_result: Optional[ClassificationResult] = None,
|
|
878
|
+
project_type: Optional[ProjectType] = None,
|
|
477
879
|
document_type_name: Optional[str] = None,
|
|
478
880
|
) -> Union[ExtractionResponse, ExtractionResponseIXP]:
|
|
479
881
|
"""Asynchronously version of the [`extract`][uipath._services.documents_service.DocumentsService.extract] method."""
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
882
|
+
project_type = _validate_extract_params_and_get_project_type(
|
|
883
|
+
project_name=project_name,
|
|
884
|
+
file=file,
|
|
885
|
+
file_path=file_path,
|
|
886
|
+
classification_result=classification_result,
|
|
887
|
+
project_type=project_type,
|
|
888
|
+
document_type_name=document_type_name,
|
|
889
|
+
)
|
|
488
890
|
|
|
489
891
|
project_id = await self._get_project_id_and_validate_tag_async(
|
|
490
|
-
|
|
892
|
+
tag=tag,
|
|
893
|
+
project_name=project_name,
|
|
894
|
+
project_type=project_type,
|
|
895
|
+
classification_result=classification_result,
|
|
491
896
|
)
|
|
492
897
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
898
|
+
document_id = await self._get_document_id_async(
|
|
899
|
+
project_id=project_id,
|
|
900
|
+
file=file,
|
|
901
|
+
file_path=file_path,
|
|
902
|
+
classification_result=classification_result,
|
|
903
|
+
)
|
|
498
904
|
|
|
499
905
|
document_type_id = await self._get_document_type_id_async(
|
|
500
906
|
project_id=project_id,
|
|
501
907
|
document_type_name=document_type_name,
|
|
502
908
|
project_type=project_type,
|
|
909
|
+
classification_result=classification_result,
|
|
503
910
|
)
|
|
504
911
|
|
|
505
912
|
operation_id = await self._start_extraction_async(
|
uipath/models/documents.py
CHANGED
|
@@ -151,3 +151,67 @@ class ValidatedResult(BaseModel):
|
|
|
151
151
|
|
|
152
152
|
document_id: str = Field(alias="DocumentId")
|
|
153
153
|
results_document: dict = Field(alias="ResultsDocument") # type: ignore
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
class Reference(BaseModel):
|
|
157
|
+
model_config = ConfigDict(
|
|
158
|
+
serialize_by_alias=True,
|
|
159
|
+
validate_by_alias=True,
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
text_start_index: int = Field(alias="TextStartIndex")
|
|
163
|
+
text_length: int = Field(alias="TextLength")
|
|
164
|
+
tokens: List[str] = Field(alias="Tokens")
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class DocumentBounds(BaseModel):
|
|
168
|
+
model_config = ConfigDict(
|
|
169
|
+
serialize_by_alias=True,
|
|
170
|
+
validate_by_alias=True,
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
start_page: int = Field(alias="StartPage")
|
|
174
|
+
page_count: int = Field(alias="PageCount")
|
|
175
|
+
text_start_index: int = Field(alias="TextStartIndex")
|
|
176
|
+
text_length: int = Field(alias="TextLength")
|
|
177
|
+
page_range: str = Field(alias="PageRange")
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class ClassificationResult(BaseModel):
|
|
181
|
+
"""A model representing the result of a document classification.
|
|
182
|
+
|
|
183
|
+
Attributes:
|
|
184
|
+
document_id (str): The ID of the classified document.
|
|
185
|
+
document_type_id (str): The ID of the predicted document type.
|
|
186
|
+
confidence (float): The confidence score of the classification.
|
|
187
|
+
ocr_confidence (float): The OCR confidence score of the document.
|
|
188
|
+
reference (Reference): The reference information for the classified document.
|
|
189
|
+
document_bounds (DocumentBounds): The bounds of the document in terms of pages and text.
|
|
190
|
+
classifier_name (str): The name of the classifier used.
|
|
191
|
+
project_id (str): The ID of the project associated with the classification.
|
|
192
|
+
"""
|
|
193
|
+
|
|
194
|
+
model_config = ConfigDict(
|
|
195
|
+
serialize_by_alias=True,
|
|
196
|
+
validate_by_alias=True,
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
document_id: str = Field(alias="DocumentId")
|
|
200
|
+
document_type_id: str = Field(alias="DocumentTypeId")
|
|
201
|
+
confidence: float = Field(alias="Confidence")
|
|
202
|
+
ocr_confidence: float = Field(alias="OcrConfidence")
|
|
203
|
+
reference: Reference = Field(alias="Reference")
|
|
204
|
+
document_bounds: DocumentBounds = Field(alias="DocumentBounds")
|
|
205
|
+
classifier_name: str = Field(alias="ClassifierName")
|
|
206
|
+
project_id: str = Field(alias="ProjectId")
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
class ClassificationResponse(BaseModel):
|
|
210
|
+
model_config = ConfigDict(
|
|
211
|
+
serialize_by_alias=True,
|
|
212
|
+
validate_by_alias=True,
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
classification_results: List[ClassificationResult] = Field(
|
|
216
|
+
alias="classificationResults"
|
|
217
|
+
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: uipath
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.119
|
|
4
4
|
Summary: Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools.
|
|
5
5
|
Project-URL: Homepage, https://uipath.com
|
|
6
6
|
Project-URL: Repository, https://github.com/UiPath/uipath-python
|
|
@@ -109,7 +109,7 @@ uipath/_resources/AGENTS.md,sha256=nRQNAVeEBaBvuMzXw8uXtMnGebLClUgwIMlgb8_qU9o,1
|
|
|
109
109
|
uipath/_resources/CLAUDE.md,sha256=kYsckFWTVe948z_fNWLysCHvi9_YpchBXl3s1Ek03lU,10
|
|
110
110
|
uipath/_resources/CLI_REFERENCE.md,sha256=v6pVR2jbBP7hTXwAwi3Ia5C96BfDKs4xGCCUOmsbEBM,6530
|
|
111
111
|
uipath/_resources/REQUIRED_STRUCTURE.md,sha256=3laqGiNa3kauJ7jRI1d7w_fWKUDkqYBjcTT_6_8FAGk,1417
|
|
112
|
-
uipath/_resources/SDK_REFERENCE.md,sha256=
|
|
112
|
+
uipath/_resources/SDK_REFERENCE.md,sha256=lvQxxdsHi-kzur2C1L4fJ6cEvjVdJPUNSX8UMofgqUQ,19485
|
|
113
113
|
uipath/_services/__init__.py,sha256=_LNy4u--VlhVtTO66bULbCoBjyJBTuyh9jnzjWrv-h4,1140
|
|
114
114
|
uipath/_services/_base_service.py,sha256=x9-9jhPzn9Z16KRdFHhJNvV-FZHvTniMsDfxlS4Cutk,5782
|
|
115
115
|
uipath/_services/actions_service.py,sha256=2RPMR-hFMsOlqEyjIf3aF7-lrf57jdrSD0pBjj0Kyko,16040
|
|
@@ -119,7 +119,7 @@ uipath/_services/attachments_service.py,sha256=NPQYK7CGjfBaNT_1S5vEAfODmOChTbQZf
|
|
|
119
119
|
uipath/_services/buckets_service.py,sha256=5s8tuivd7GUZYj774DDUYTa0axxlUuesc4EBY1V5sdk,18496
|
|
120
120
|
uipath/_services/connections_service.py,sha256=tKJHHOKQYKR6LkgB-V_2d0vFpLEdFeMzwj_xmBVHUDw,18416
|
|
121
121
|
uipath/_services/context_grounding_service.py,sha256=Pjx-QQQEiSKD-hY6ityj3QUSALN3fIcKLLHr_NZ0d_g,37117
|
|
122
|
-
uipath/_services/documents_service.py,sha256=
|
|
122
|
+
uipath/_services/documents_service.py,sha256=2mPZzmOl2r5i8RYvdeRSJtEFWSSsiXqIauTgNTW75s4,45341
|
|
123
123
|
uipath/_services/entities_service.py,sha256=QKCLE6wRgq3HZraF-M2mljy-8il4vsNHrQhUgkewVVk,14028
|
|
124
124
|
uipath/_services/external_application_service.py,sha256=gZhnGgLn7ZYUZzZF7AumB14QEPanVY-D_02FqEcAFtw,5478
|
|
125
125
|
uipath/_services/folder_service.py,sha256=9JqgjKhWD-G_KUnfUTP2BADxL6OK9QNZsBsWZHAULdE,2749
|
|
@@ -205,7 +205,7 @@ uipath/models/buckets.py,sha256=N3Lj_dVCv709-ywhOOdyCSvsuLn41eGuAfSiik6Q6F8,1285
|
|
|
205
205
|
uipath/models/connections.py,sha256=jmzlfnddqlxjmiVhqsETRV6TQPH3fFqJGsygG0gUf7g,2745
|
|
206
206
|
uipath/models/context_grounding.py,sha256=3MaF2Fv2QYle8UUWvKGkCN5XGpx2T4a34fdbBqJ2fCs,1137
|
|
207
207
|
uipath/models/context_grounding_index.py,sha256=OhRyxZDHDSrEmBFK0-JLqMMMT64jir4XkHtQ54IKtc0,2683
|
|
208
|
-
uipath/models/documents.py,sha256=
|
|
208
|
+
uipath/models/documents.py,sha256=gh063bG0pl4YGThWQIgprwRCKxnKVoMOZrXDfDEVnQw,7337
|
|
209
209
|
uipath/models/entities.py,sha256=x6jbq4o_QhgL_pCgvHFsp9O8l333kQhn8e9ZCBs72UM,9823
|
|
210
210
|
uipath/models/errors.py,sha256=WCxxHBlLzLF17YxjqsFkkyBLwEQM_dc6fFU5qmBjD4A,597
|
|
211
211
|
uipath/models/exceptions.py,sha256=f71VsUyonK2uuH1Cs0tpP6f9dec6v6cffL1Z9EjTxm0,1870
|
|
@@ -225,8 +225,8 @@ uipath/tracing/_utils.py,sha256=zMjiKjNpSN3YQNEU4-u5AAvPtUsi8QuEqNLya89jfAU,1446
|
|
|
225
225
|
uipath/utils/__init__.py,sha256=VD-KXFpF_oWexFg6zyiWMkxl2HM4hYJMIUDZ1UEtGx0,105
|
|
226
226
|
uipath/utils/_endpoints_manager.py,sha256=tnF_FiCx8qI2XaJDQgYkMN_gl9V0VqNR1uX7iawuLp8,8230
|
|
227
227
|
uipath/utils/dynamic_schema.py,sha256=w0u_54MoeIAB-mf3GmwX1A_X8_HDrRy6p998PvX9evY,3839
|
|
228
|
-
uipath-2.1.
|
|
229
|
-
uipath-2.1.
|
|
230
|
-
uipath-2.1.
|
|
231
|
-
uipath-2.1.
|
|
232
|
-
uipath-2.1.
|
|
228
|
+
uipath-2.1.119.dist-info/METADATA,sha256=3bFAJBRf1iXbqhxg8hQUgj3ggLWI6Sptx_R-iQbunbM,6626
|
|
229
|
+
uipath-2.1.119.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
230
|
+
uipath-2.1.119.dist-info/entry_points.txt,sha256=9C2_29U6Oq1ExFu7usihR-dnfIVNSKc-0EFbh0rskB4,43
|
|
231
|
+
uipath-2.1.119.dist-info/licenses/LICENSE,sha256=-KBavWXepyDjimmzH5fVAsi-6jNVpIKFc2kZs0Ri4ng,1058
|
|
232
|
+
uipath-2.1.119.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|