uipath 2.1.111__py3-none-any.whl → 2.1.113__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.

@@ -1,7 +1,8 @@
1
1
  import asyncio
2
2
  import time
3
+ from contextlib import nullcontext
3
4
  from pathlib import Path
4
- from typing import Any, Awaitable, Callable, Dict, List, Optional, Set, Tuple
5
+ from typing import Any, Awaitable, Callable, Dict, List, Optional, Set, Tuple, Union
5
6
  from uuid import UUID
6
7
 
7
8
  from httpx._types import FileContent
@@ -13,6 +14,8 @@ from .._utils import Endpoint
13
14
  from ..models.documents import (
14
15
  ActionPriority,
15
16
  ExtractionResponse,
17
+ ExtractionResponseIXP,
18
+ ProjectType,
16
19
  ValidatedResult,
17
20
  ValidationAction,
18
21
  )
@@ -41,11 +44,13 @@ class DocumentsService(FolderContext, BaseService):
41
44
  "X-UiPath-Internal-ConsumptionSourceType": "CodedAgents",
42
45
  }
43
46
 
44
- def _get_project_id_by_name(self, project_name: str) -> str:
47
+ def _get_project_id_by_name(
48
+ self, project_name: str, project_type: ProjectType
49
+ ) -> str:
45
50
  response = self.request(
46
51
  "GET",
47
52
  url=Endpoint("/du_/api/framework/projects"),
48
- params={"api-version": 1.1, "type": "IXP"},
53
+ params={"api-version": 1.1, "type": project_type.value},
49
54
  headers=self._get_common_headers(),
50
55
  )
51
56
 
@@ -58,11 +63,13 @@ class DocumentsService(FolderContext, BaseService):
58
63
  except StopIteration:
59
64
  raise ValueError(f"Project '{project_name}' not found.") from None
60
65
 
61
- async def _get_project_id_by_name_async(self, project_name: str) -> str:
66
+ async def _get_project_id_by_name_async(
67
+ self, project_name: str, project_type: ProjectType
68
+ ) -> str:
62
69
  response = await self.request_async(
63
70
  "GET",
64
71
  url=Endpoint("/du_/api/framework/projects"),
65
- params={"api-version": 1.1, "type": "IXP"},
72
+ params={"api-version": 1.1, "type": project_type.value},
66
73
  headers=self._get_common_headers(),
67
74
  )
68
75
 
@@ -93,8 +100,10 @@ class DocumentsService(FolderContext, BaseService):
93
100
  )
94
101
  return {tag["name"] for tag in response.json().get("tags", [])}
95
102
 
96
- def _get_project_id_and_validate_tag(self, project_name: str, tag: str) -> str:
97
- project_id = self._get_project_id_by_name(project_name)
103
+ def _get_project_id_and_validate_tag(
104
+ self, project_name: str, project_type: ProjectType, tag: str
105
+ ) -> str:
106
+ project_id = self._get_project_id_by_name(project_name, project_type)
98
107
  tags = self._get_project_tags(project_id)
99
108
  if tag not in tags:
100
109
  raise ValueError(
@@ -104,9 +113,11 @@ class DocumentsService(FolderContext, BaseService):
104
113
  return project_id
105
114
 
106
115
  async def _get_project_id_and_validate_tag_async(
107
- self, project_name: str, tag: str
116
+ self, project_name: str, project_type: ProjectType, tag: str
108
117
  ) -> str:
109
- project_id = await self._get_project_id_by_name_async(project_name)
118
+ project_id = await self._get_project_id_by_name_async(
119
+ project_name, project_type
120
+ )
110
121
  tags = await self._get_project_tags_async(project_id)
111
122
  if tag not in tags:
112
123
  raise ValueError(
@@ -147,16 +158,71 @@ class DocumentsService(FolderContext, BaseService):
147
158
  )
148
159
  ).json()["documentId"]
149
160
 
161
+ def _get_document_type_id(
162
+ self,
163
+ project_id: str,
164
+ document_type_name: Optional[str],
165
+ project_type: ProjectType,
166
+ ) -> str:
167
+ if project_type == ProjectType.IXP:
168
+ return str(UUID(int=0))
169
+
170
+ response = self.request(
171
+ "GET",
172
+ url=Endpoint(f"/du_/api/framework/projects/{project_id}/document-types"),
173
+ params={"api-version": 1.1},
174
+ headers=self._get_common_headers(),
175
+ )
176
+
177
+ try:
178
+ return next(
179
+ extractor["id"]
180
+ for extractor in response.json().get("documentTypes", [])
181
+ if extractor["name"].lower() == document_type_name.lower() # type: ignore
182
+ )
183
+ except StopIteration:
184
+ raise ValueError(
185
+ f"Document type '{document_type_name}' not found."
186
+ ) from None
187
+
188
+ async def _get_document_type_id_async(
189
+ self,
190
+ project_id: str,
191
+ document_type_name: Optional[str],
192
+ project_type: ProjectType,
193
+ ) -> str:
194
+ if project_type == ProjectType.IXP:
195
+ return str(UUID(int=0))
196
+
197
+ response = await self.request_async(
198
+ "GET",
199
+ url=Endpoint(f"/du_/api/framework/projects/{project_id}/document-types"),
200
+ params={"api-version": 1.1},
201
+ headers=self._get_common_headers(),
202
+ )
203
+
204
+ try:
205
+ return next(
206
+ extractor["id"]
207
+ for extractor in response.json().get("documentTypes", [])
208
+ if extractor["name"].lower() == document_type_name.lower() # type: ignore
209
+ )
210
+ except StopIteration:
211
+ raise ValueError(
212
+ f"Document type '{document_type_name}' not found."
213
+ ) from None
214
+
150
215
  def _start_extraction(
151
216
  self,
152
217
  project_id: str,
153
218
  tag: str,
219
+ document_type_id: str,
154
220
  document_id: str,
155
221
  ) -> str:
156
222
  return self.request(
157
223
  "POST",
158
224
  url=Endpoint(
159
- f"/du_/api/framework/projects/{project_id}/{tag}/document-types/{UUID(int=0)}/extraction/start"
225
+ f"/du_/api/framework/projects/{project_id}/{tag}/document-types/{document_type_id}/extraction/start"
160
226
  ),
161
227
  params={"api-version": 1.1},
162
228
  headers=self._get_common_headers(),
@@ -167,13 +233,14 @@ class DocumentsService(FolderContext, BaseService):
167
233
  self,
168
234
  project_id: str,
169
235
  tag: str,
236
+ document_type_id: str,
170
237
  document_id: str,
171
238
  ) -> str:
172
239
  return (
173
240
  await self.request_async(
174
241
  "POST",
175
242
  url=Endpoint(
176
- f"/du_/api/framework/projects/{project_id}/{tag}/document-types/{UUID(int=0)}/extraction/start"
243
+ f"/du_/api/framework/projects/{project_id}/{tag}/document-types/{document_type_id}/extraction/start"
177
244
  ),
178
245
  params={"api-version": 1.1},
179
246
  headers=self._get_common_headers(),
@@ -183,7 +250,7 @@ class DocumentsService(FolderContext, BaseService):
183
250
 
184
251
  def _wait_for_operation(
185
252
  self,
186
- result_getter: Callable[[], Tuple[str, Any]],
253
+ result_getter: Callable[[], Tuple[Any, Optional[Any], Optional[Any]]],
187
254
  wait_statuses: List[str],
188
255
  success_status: str,
189
256
  ) -> Any:
@@ -195,19 +262,23 @@ class DocumentsService(FolderContext, BaseService):
195
262
  status in wait_statuses
196
263
  and (time.monotonic() - start_time) < POLLING_TIMEOUT
197
264
  ):
198
- status, result = result_getter()
265
+ status, error, result = result_getter()
199
266
  time.sleep(POLLING_INTERVAL)
200
267
 
201
268
  if status != success_status:
202
269
  if time.monotonic() - start_time >= POLLING_TIMEOUT:
203
270
  raise TimeoutError("Operation timed out.")
204
- raise RuntimeError(f"Operation failed with status: {status}")
271
+ raise RuntimeError(
272
+ f"Operation failed with status: {status}, error: {error}"
273
+ )
205
274
 
206
275
  return result
207
276
 
208
277
  async def _wait_for_operation_async(
209
278
  self,
210
- result_getter: Callable[[], Awaitable[Tuple[str, Any]]],
279
+ result_getter: Callable[
280
+ [], Awaitable[Tuple[Any, Optional[Any], Optional[Any]]]
281
+ ],
211
282
  wait_statuses: List[str],
212
283
  success_status: str,
213
284
  ) -> Any:
@@ -219,55 +290,80 @@ class DocumentsService(FolderContext, BaseService):
219
290
  status in wait_statuses
220
291
  and (time.monotonic() - start_time) < POLLING_TIMEOUT
221
292
  ):
222
- status, result = await result_getter()
293
+ status, error, result = await result_getter()
223
294
  await asyncio.sleep(POLLING_INTERVAL)
224
295
 
225
296
  if status != success_status:
226
297
  if time.monotonic() - start_time >= POLLING_TIMEOUT:
227
298
  raise TimeoutError("Operation timed out.")
228
- raise RuntimeError(f"Operation failed with status: {status}")
299
+ raise RuntimeError(
300
+ f"Operation failed with status: {status}, error: {error}"
301
+ )
229
302
 
230
303
  return result
231
304
 
232
305
  def _wait_for_extraction(
233
- self, project_id: str, tag: str, operation_id: str
234
- ) -> ExtractionResponse:
235
- extraction_response = self._wait_for_operation(
236
- result_getter=lambda: (
237
- (
238
- result := self.request(
239
- method="GET",
240
- url=Endpoint(
241
- f"/du_/api/framework/projects/{project_id}/{tag}/document-types/{UUID(int=0)}/extraction/result/{operation_id}"
242
- ),
243
- params={"api-version": 1.1},
244
- headers=self._get_common_headers(),
245
- ).json()
246
- )["status"],
306
+ self,
307
+ project_id: str,
308
+ tag: str,
309
+ document_type_id: str,
310
+ operation_id: str,
311
+ project_type: ProjectType,
312
+ ) -> Union[ExtractionResponse, ExtractionResponseIXP]:
313
+ def result_getter() -> Tuple[str, str, Any]:
314
+ result = self.request(
315
+ method="GET",
316
+ url=Endpoint(
317
+ f"/du_/api/framework/projects/{project_id}/{tag}/document-types/{document_type_id}/extraction/result/{operation_id}"
318
+ ),
319
+ params={"api-version": 1.1},
320
+ headers=self._get_common_headers(),
321
+ ).json()
322
+ return (
323
+ result["status"],
324
+ result.get("error", None),
247
325
  result.get("result", None),
248
- ),
326
+ )
327
+
328
+ extraction_response = self._wait_for_operation(
329
+ result_getter=result_getter,
249
330
  wait_statuses=["NotStarted", "Running"],
250
331
  success_status="Succeeded",
251
332
  )
252
333
 
253
334
  extraction_response["projectId"] = project_id
254
335
  extraction_response["tag"] = tag
336
+ extraction_response["documentTypeId"] = document_type_id
337
+
338
+ if project_type == ProjectType.IXP:
339
+ return ExtractionResponseIXP.model_validate(extraction_response)
340
+
255
341
  return ExtractionResponse.model_validate(extraction_response)
256
342
 
257
343
  async def _wait_for_extraction_async(
258
- self, project_id: str, tag: str, operation_id: str
259
- ) -> ExtractionResponse:
260
- async def result_getter() -> Tuple[str, Any]:
261
- result = await self.request_async(
262
- method="GET",
263
- url=Endpoint(
264
- f"/du_/api/framework/projects/{project_id}/{tag}/document-types/{UUID(int=0)}/extraction/result/{operation_id}"
265
- ),
266
- params={"api-version": 1.1},
267
- headers=self._get_common_headers(),
344
+ self,
345
+ project_id: str,
346
+ tag: str,
347
+ document_type_id: str,
348
+ operation_id: str,
349
+ project_type: ProjectType,
350
+ ) -> Union[ExtractionResponse, ExtractionResponseIXP]:
351
+ async def result_getter() -> Tuple[str, str, Any]:
352
+ result = (
353
+ await self.request_async(
354
+ method="GET",
355
+ url=Endpoint(
356
+ f"/du_/api/framework/projects/{project_id}/{tag}/document-types/{document_type_id}/extraction/result/{operation_id}"
357
+ ),
358
+ params={"api-version": 1.1},
359
+ headers=self._get_common_headers(),
360
+ )
361
+ ).json()
362
+ return (
363
+ result["status"],
364
+ result.get("error", None),
365
+ result.get("result", None),
268
366
  )
269
- json_result = result.json()
270
- return json_result["status"], json_result.get("result", None)
271
367
 
272
368
  extraction_response = await self._wait_for_operation_async(
273
369
  result_getter=result_getter,
@@ -277,6 +373,11 @@ class DocumentsService(FolderContext, BaseService):
277
373
 
278
374
  extraction_response["projectId"] = project_id
279
375
  extraction_response["tag"] = tag
376
+ extraction_response["documentTypeId"] = document_type_id
377
+
378
+ if project_type == ProjectType.IXP:
379
+ return ExtractionResponseIXP.model_validate(extraction_response)
380
+
280
381
  return ExtractionResponse.model_validate(extraction_response)
281
382
 
282
383
  @traced(name="documents_extract", run_type="uipath")
@@ -286,14 +387,18 @@ class DocumentsService(FolderContext, BaseService):
286
387
  tag: str,
287
388
  file: Optional[FileContent] = None,
288
389
  file_path: Optional[str] = None,
289
- ) -> ExtractionResponse:
390
+ project_type: ProjectType = ProjectType.IXP,
391
+ document_type_name: Optional[str] = None,
392
+ ) -> Union[ExtractionResponse, ExtractionResponseIXP]:
290
393
  """Extract predicted data from a document using an IXP project.
291
394
 
292
395
  Args:
293
- project_name (str): Name of the IXP project. Details about IXP projects can be found in the [official documentation](https://docs.uipath.com/ixp/automation-cloud/latest/overview/managing-projects#creating-a-new-project).
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.
294
397
  tag (str): Tag of the published project version.
295
398
  file (FileContent, optional): The document file to be processed.
296
399
  file_path (str, optional): Path to the document file to be processed.
400
+ project_type (ProjectType, optional): Type of the project. Defaults to `ProjectType.IXP`.
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`.
297
402
 
298
403
  Note:
299
404
  Either `file` or `file_path` must be provided, but not both.
@@ -302,38 +407,63 @@ class DocumentsService(FolderContext, BaseService):
302
407
  ExtractionResponse: The extraction result containing predicted data.
303
408
 
304
409
  Examples:
410
+ IXP projects:
305
411
  ```python
306
412
  with open("path/to/document.pdf", "rb") as file:
307
413
  extraction_response = service.extract(
308
- project_name="MyProject",
414
+ project_name="MyIXPProjectName",
309
415
  tag="live",
310
416
  file=file,
311
417
  )
312
418
  ```
419
+
420
+ DU Modern projects:
421
+ ```python
422
+ with open("path/to/document.pdf", "rb") as file:
423
+ extraction_response = service.extract(
424
+ project_name="MyModernProjectName",
425
+ tag="Production",
426
+ file=file,
427
+ project_type=ProjectType.MODERN,
428
+ document_type_name="Receipts",
429
+ )
430
+ ```
313
431
  """
314
432
  if file is None and file_path is None:
315
433
  raise ValueError("Either `file` or `file_path` must be provided")
316
434
  if file is not None and file_path is not None:
317
435
  raise ValueError("`file` and `file_path` are mutually exclusive")
436
+ if project_type == ProjectType.MODERN and document_type_name is None:
437
+ raise ValueError(
438
+ "`document_type_name` must be provided when `project_type` is `ProjectType.MODERN`"
439
+ )
318
440
 
319
441
  project_id = self._get_project_id_and_validate_tag(
320
- project_name=project_name, tag=tag
442
+ project_name=project_name, project_type=project_type, tag=tag
321
443
  )
322
444
 
323
- if file_path is not None:
324
- with open(Path(file_path), "rb") as handle:
325
- document_id = self._start_digitization(
326
- project_id=project_id, file=handle
327
- )
328
- else:
329
- document_id = self._start_digitization(project_id=project_id, file=file) # type: ignore
445
+ with open(Path(file_path), "rb") if file_path else nullcontext(file) as handle:
446
+ document_id = self._start_digitization(project_id=project_id, file=handle) # type: ignore
447
+
448
+ document_type_id = self._get_document_type_id(
449
+ project_id=project_id,
450
+ document_type_name=document_type_name,
451
+ project_type=project_type,
452
+ )
330
453
 
331
454
  operation_id = self._start_extraction(
332
- project_id=project_id, tag=tag, document_id=document_id
455
+ project_id=project_id,
456
+ tag=tag,
457
+ document_type_id=document_type_id,
458
+ document_id=document_id,
333
459
  )
334
460
 
335
461
  return self._wait_for_extraction(
336
- project_id=project_id, tag=tag, operation_id=operation_id
462
+ project_id=project_id,
463
+ tag=tag,
464
+ document_type_id=document_type_id,
465
+ operation_id=operation_id,
466
+ project_type=project_type,
337
467
  )
338
468
 
339
469
  @traced(name="documents_extract_async", run_type="uipath")
@@ -343,40 +473,55 @@ class DocumentsService(FolderContext, BaseService):
343
473
  tag: str,
344
474
  file: Optional[FileContent] = None,
345
475
  file_path: Optional[str] = None,
346
- ) -> ExtractionResponse:
347
- """Asynchronously extract predicted data from a document using an IXP project."""
476
+ project_type: ProjectType = ProjectType.IXP,
477
+ document_type_name: Optional[str] = None,
478
+ ) -> Union[ExtractionResponse, ExtractionResponseIXP]:
479
+ """Asynchronously version of the [`extract`][uipath._services.documents_service.DocumentsService.extract] method."""
348
480
  if file is None and file_path is None:
349
481
  raise ValueError("Either `file` or `file_path` must be provided")
350
482
  if file is not None and file_path is not None:
351
483
  raise ValueError("`file` and `file_path` are mutually exclusive")
484
+ if project_type == ProjectType.MODERN and document_type_name is None:
485
+ raise ValueError(
486
+ "`document_type_name` must be provided when `project_type` is `ProjectType.MODERN`"
487
+ )
352
488
 
353
489
  project_id = await self._get_project_id_and_validate_tag_async(
354
- project_name=project_name, tag=tag
490
+ project_name=project_name, project_type=project_type, tag=tag
355
491
  )
356
492
 
357
- if file_path is not None:
358
- with open(Path(file_path), "rb") as handle:
359
- document_id = await self._start_digitization_async(
360
- project_id=project_id, file=handle
361
- )
362
- else:
493
+ with open(Path(file_path), "rb") if file_path else nullcontext(file) as handle:
363
494
  document_id = await self._start_digitization_async(
364
495
  project_id=project_id,
365
- file=file, # type: ignore
496
+ file=handle, # type: ignore
366
497
  )
367
498
 
499
+ document_type_id = await self._get_document_type_id_async(
500
+ project_id=project_id,
501
+ document_type_name=document_type_name,
502
+ project_type=project_type,
503
+ )
504
+
368
505
  operation_id = await self._start_extraction_async(
369
- project_id=project_id, tag=tag, document_id=document_id
506
+ project_id=project_id,
507
+ tag=tag,
508
+ document_type_id=document_type_id,
509
+ document_id=document_id,
370
510
  )
371
511
 
372
512
  return await self._wait_for_extraction_async(
373
- project_id=project_id, tag=tag, operation_id=operation_id
513
+ project_id=project_id,
514
+ tag=tag,
515
+ document_type_id=document_type_id,
516
+ operation_id=operation_id,
517
+ project_type=project_type,
374
518
  )
375
519
 
376
520
  def _start_validation(
377
521
  self,
378
522
  project_id: str,
379
523
  tag: str,
524
+ document_type_id: str,
380
525
  action_title: str,
381
526
  action_priority: ActionPriority,
382
527
  action_catalog: str,
@@ -388,7 +533,7 @@ class DocumentsService(FolderContext, BaseService):
388
533
  return self.request(
389
534
  "POST",
390
535
  url=Endpoint(
391
- f"/du_/api/framework/projects/{project_id}/{tag}/document-types/{UUID(int=0)}/validation/start"
536
+ f"/du_/api/framework/projects/{project_id}/{tag}/document-types/{document_type_id}/validation/start"
392
537
  ),
393
538
  params={"api-version": 1.1},
394
539
  headers=self._get_common_headers(),
@@ -409,6 +554,7 @@ class DocumentsService(FolderContext, BaseService):
409
554
  self,
410
555
  project_id: str,
411
556
  tag: str,
557
+ document_type_id: str,
412
558
  action_title: str,
413
559
  action_priority: ActionPriority,
414
560
  action_catalog: str,
@@ -421,7 +567,7 @@ class DocumentsService(FolderContext, BaseService):
421
567
  await self.request_async(
422
568
  "POST",
423
569
  url=Endpoint(
424
- f"/du_/api/framework/projects/{project_id}/{tag}/document-types/{UUID(int=0)}/validation/start"
570
+ f"/du_/api/framework/projects/{project_id}/{tag}/document-types/{document_type_id}/validation/start"
425
571
  ),
426
572
  params={"api-version": 1.1},
427
573
  headers=self._get_common_headers(),
@@ -440,25 +586,25 @@ class DocumentsService(FolderContext, BaseService):
440
586
  ).json()["operationId"]
441
587
 
442
588
  def _get_validation_result(
443
- self, project_id: str, tag: str, operation_id: str
589
+ self, project_id: str, tag: str, document_type_id: str, operation_id: str
444
590
  ) -> Dict: # type: ignore
445
591
  return self.request(
446
592
  method="GET",
447
593
  url=Endpoint(
448
- f"/du_/api/framework/projects/{project_id}/{tag}/document-types/{UUID(int=0)}/validation/result/{operation_id}"
594
+ f"/du_/api/framework/projects/{project_id}/{tag}/document-types/{document_type_id}/validation/result/{operation_id}"
449
595
  ),
450
596
  params={"api-version": 1.1},
451
597
  headers=self._get_common_headers(),
452
598
  ).json()
453
599
 
454
600
  async def _get_validation_result_async(
455
- self, project_id: str, tag: str, operation_id: str
601
+ self, project_id: str, tag: str, document_type_id: str, operation_id: str
456
602
  ) -> Dict: # type: ignore
457
603
  return (
458
604
  await self.request_async(
459
605
  method="GET",
460
606
  url=Endpoint(
461
- f"/du_/api/framework/projects/{project_id}/{tag}/document-types/{UUID(int=0)}/validation/result/{operation_id}"
607
+ f"/du_/api/framework/projects/{project_id}/{tag}/document-types/{document_type_id}/validation/result/{operation_id}"
462
608
  ),
463
609
  params={"api-version": 1.1},
464
610
  headers=self._get_common_headers(),
@@ -466,43 +612,58 @@ class DocumentsService(FolderContext, BaseService):
466
612
  ).json()
467
613
 
468
614
  def _wait_for_create_validation_action(
469
- self, project_id: str, tag: str, operation_id: str
615
+ self, project_id: str, tag: str, document_type_id: str, operation_id: str
470
616
  ) -> ValidationAction:
471
- response = self._wait_for_operation(
472
- lambda: (
473
- (
474
- result := self._get_validation_result(
475
- project_id=project_id, tag=tag, operation_id=operation_id
476
- )
477
- )["status"],
617
+ def result_getter() -> Tuple[Any, Optional[Any], Optional[Any]]:
618
+ result = self._get_validation_result(
619
+ project_id=project_id,
620
+ tag=tag,
621
+ document_type_id=document_type_id,
622
+ operation_id=operation_id,
623
+ )
624
+ return (
625
+ result["status"],
626
+ result.get("error", None),
478
627
  result.get("result", None),
479
- ),
628
+ )
629
+
630
+ response = self._wait_for_operation(
631
+ result_getter=result_getter,
480
632
  wait_statuses=["NotStarted", "Running"],
481
633
  success_status="Succeeded",
482
634
  )
483
635
 
484
636
  response["projectId"] = project_id
485
637
  response["tag"] = tag
638
+ response["documentTypeId"] = document_type_id
486
639
  response["operationId"] = operation_id
487
640
  return ValidationAction.model_validate(response)
488
641
 
489
642
  async def _wait_for_create_validation_action_async(
490
- self, project_id: str, tag: str, operation_id: str
643
+ self, project_id: str, tag: str, document_type_id: str, operation_id: str
491
644
  ) -> ValidationAction:
492
- async def result_getter() -> Tuple[str, Any]:
645
+ async def result_getter_async() -> Tuple[Any, Optional[Any], Optional[Any]]:
493
646
  result = await self._get_validation_result_async(
494
- project_id=project_id, tag=tag, operation_id=operation_id
647
+ project_id=project_id,
648
+ tag=tag,
649
+ document_type_id=document_type_id,
650
+ operation_id=operation_id,
651
+ )
652
+ return (
653
+ result["status"],
654
+ result.get("error", None),
655
+ result.get("result", None),
495
656
  )
496
- return result["status"], result.get("result", None)
497
657
 
498
658
  response = await self._wait_for_operation_async(
499
- result_getter=result_getter,
659
+ result_getter=result_getter_async,
500
660
  wait_statuses=["NotStarted", "Running"],
501
661
  success_status="Succeeded",
502
662
  )
503
663
 
504
664
  response["projectId"] = project_id
505
665
  response["tag"] = tag
666
+ response["documentTypeId"] = document_type_id
506
667
  response["operationId"] = operation_id
507
668
  return ValidationAction.model_validate(response)
508
669
 
@@ -546,7 +707,8 @@ class DocumentsService(FolderContext, BaseService):
546
707
  """
547
708
  operation_id = self._start_validation(
548
709
  project_id=extraction_response.project_id,
549
- tag=extraction_response.tag, # should I validate tag again?
710
+ tag=extraction_response.tag,
711
+ document_type_id=extraction_response.document_type_id,
550
712
  action_title=action_title,
551
713
  action_priority=action_priority,
552
714
  action_catalog=action_catalog,
@@ -559,6 +721,7 @@ class DocumentsService(FolderContext, BaseService):
559
721
  return self._wait_for_create_validation_action(
560
722
  project_id=extraction_response.project_id,
561
723
  tag=extraction_response.tag,
724
+ document_type_id=extraction_response.document_type_id,
562
725
  operation_id=operation_id,
563
726
  )
564
727
 
@@ -573,11 +736,11 @@ class DocumentsService(FolderContext, BaseService):
573
736
  storage_bucket_directory_path: str,
574
737
  extraction_response: ExtractionResponse,
575
738
  ) -> ValidationAction:
576
- """Asynchronously create a validation action for a document based on the extraction response."""
577
- # Add reference to sync method docstring
739
+ """Asynchronous version of the [`create_validation_action`][uipath._services.documents_service.DocumentsService.create_validation_action] method."""
578
740
  operation_id = await self._start_validation_async(
579
741
  project_id=extraction_response.project_id,
580
- tag=extraction_response.tag, # should I validate tag again?
742
+ tag=extraction_response.tag,
743
+ document_type_id=extraction_response.document_type_id,
581
744
  action_title=action_title,
582
745
  action_priority=action_priority,
583
746
  action_catalog=action_catalog,
@@ -590,6 +753,7 @@ class DocumentsService(FolderContext, BaseService):
590
753
  return await self._wait_for_create_validation_action_async(
591
754
  project_id=extraction_response.project_id,
592
755
  tag=extraction_response.tag,
756
+ document_type_id=extraction_response.document_type_id,
593
757
  operation_id=operation_id,
594
758
  )
595
759
 
@@ -613,17 +777,22 @@ class DocumentsService(FolderContext, BaseService):
613
777
  validated_result = service.get_validation_result(validation_action)
614
778
  ```
615
779
  """
616
- response = self._wait_for_operation(
617
- result_getter=lambda: (
618
- (
619
- result := self._get_validation_result(
620
- project_id=validation_action.project_id,
621
- tag=validation_action.tag,
622
- operation_id=validation_action.operation_id,
623
- )
624
- )["result"]["actionStatus"],
780
+
781
+ def result_getter() -> Tuple[str, None, Any]:
782
+ result = self._get_validation_result(
783
+ project_id=validation_action.project_id,
784
+ tag=validation_action.tag,
785
+ document_type_id=validation_action.document_type_id,
786
+ operation_id=validation_action.operation_id,
787
+ )
788
+ return (
789
+ result["result"]["actionStatus"],
790
+ None,
625
791
  result["result"].get("validatedExtractionResults", None),
626
- ),
792
+ )
793
+
794
+ response = self._wait_for_operation(
795
+ result_getter=result_getter,
627
796
  wait_statuses=["Unassigned", "Pending"],
628
797
  success_status="Completed",
629
798
  )
@@ -634,16 +803,19 @@ class DocumentsService(FolderContext, BaseService):
634
803
  async def get_validation_result_async(
635
804
  self, validation_action: ValidationAction
636
805
  ) -> ValidatedResult:
637
- """Asynchronously get the result of a validation action."""
806
+ """Asynchronous version of the [`get_validation_result`][uipath._services.documents_service.DocumentsService.get_validation_result] method."""
638
807
 
639
- async def result_getter() -> Tuple[str, Any]:
808
+ async def result_getter() -> Tuple[str, None, Any]:
640
809
  result = await self._get_validation_result_async(
641
810
  project_id=validation_action.project_id,
642
811
  tag=validation_action.tag,
812
+ document_type_id=validation_action.document_type_id,
643
813
  operation_id=validation_action.operation_id,
644
814
  )
645
- return result["result"]["actionStatus"], result["result"].get(
646
- "validatedExtractionResults", None
815
+ return (
816
+ result["result"]["actionStatus"],
817
+ None,
818
+ result["result"].get("validatedExtractionResults", None),
647
819
  )
648
820
 
649
821
  response = await self._wait_for_operation_async(