uipath 2.1.118__py3-none-any.whl → 2.1.121__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/_cli/_evals/_progress_reporter.py +10 -8
- uipath/_cli/_evals/_runtime.py +2 -0
- uipath/_cli/_utils/_constants.py +0 -2
- uipath/_cli/cli_eval.py +14 -3
- uipath/_cli/cli_init.py +2 -3
- uipath/_cli/cli_pack.py +3 -3
- uipath/_cli/cli_pull.py +2 -4
- uipath/_cli/cli_push.py +2 -5
- uipath/_config.py +38 -0
- uipath/_events/_events.py +1 -0
- uipath/_resources/CLI_REFERENCE.md +2 -0
- uipath/_resources/SDK_REFERENCE.md +9 -3
- uipath/_services/documents_service.py +466 -59
- uipath/_utils/constants.py +2 -0
- uipath/models/documents.py +64 -0
- uipath/tracing/_otel_exporters.py +58 -22
- uipath/tracing/_utils.py +64 -34
- {uipath-2.1.118.dist-info → uipath-2.1.121.dist-info}/METADATA +1 -1
- {uipath-2.1.118.dist-info → uipath-2.1.121.dist-info}/RECORD +22 -22
- {uipath-2.1.118.dist-info → uipath-2.1.121.dist-info}/WHEEL +0 -0
- {uipath-2.1.118.dist-info → uipath-2.1.121.dist-info}/entry_points.txt +0 -0
- {uipath-2.1.118.dist-info → uipath-2.1.121.dist-info}/licenses/LICENSE +0 -0
|
@@ -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/_utils/constants.py
CHANGED
|
@@ -12,6 +12,7 @@ ENV_ROBOT_KEY = "UIPATH_ROBOT_KEY"
|
|
|
12
12
|
ENV_TENANT_ID = "UIPATH_TENANT_ID"
|
|
13
13
|
ENV_ORGANIZATION_ID = "UIPATH_ORGANIZATION_ID"
|
|
14
14
|
ENV_TELEMETRY_ENABLED = "UIPATH_TELEMETRY_ENABLED"
|
|
15
|
+
ENV_UIPATH_PROJECT_ID = "UIPATH_PROJECT_ID"
|
|
15
16
|
|
|
16
17
|
# Headers
|
|
17
18
|
HEADER_FOLDER_KEY = "x-uipath-folderkey"
|
|
@@ -47,6 +48,7 @@ COMMUNITY_agents_SUFFIX = "-community-agents"
|
|
|
47
48
|
|
|
48
49
|
# File names
|
|
49
50
|
UIPATH_CONFIG_FILE = "uipath.json"
|
|
51
|
+
UIPATH_BINDINGS_FILE = "bindings.json"
|
|
50
52
|
|
|
51
53
|
# Evaluators
|
|
52
54
|
CUSTOM_EVALUATOR_PREFIX = "file://"
|