Skip to content

Commit 5ff19e1

Browse files
fix(documents): improve typing and naming
1 parent 728ebd6 commit 5ff19e1

File tree

6 files changed

+107
-955
lines changed

6 files changed

+107
-955
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath"
3-
version = "2.1.119"
3+
version = "2.1.120"
44
description = "Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools."
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.10"

src/uipath/_services/documents_service.py

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from typing import Any, Awaitable, Callable, Dict, List, Optional, Set, Tuple, Union
66
from uuid import UUID
77

8-
from httpx._types import FileContent
9-
108
from .._config import Config
119
from .._execution_context import ExecutionContext
1210
from .._folder_context import FolderContext
@@ -17,8 +15,8 @@
1715
ClassificationResult,
1816
ExtractionResponse,
1917
ExtractionResponseIXP,
18+
FileContent,
2019
ProjectType,
21-
ValidatedResult,
2220
ValidationAction,
2321
)
2422
from ..tracing._traced import traced
@@ -512,6 +510,7 @@ def result_getter() -> Tuple[str, str, Any]:
512510
extraction_response["projectId"] = project_id
513511
extraction_response["tag"] = tag
514512
extraction_response["documentTypeId"] = document_type_id
513+
extraction_response["projectType"] = project_type
515514

516515
if project_type == ProjectType.IXP:
517516
return ExtractionResponseIXP.model_validate(extraction_response)
@@ -552,6 +551,7 @@ async def result_getter() -> Tuple[str, str, Any]:
552551
extraction_response["projectId"] = project_id
553552
extraction_response["tag"] = tag
554553
extraction_response["documentTypeId"] = document_type_id
554+
extraction_response["projectType"] = project_type
555555

556556
if project_type == ProjectType.IXP:
557557
return ExtractionResponseIXP.model_validate(extraction_response)
@@ -777,12 +777,13 @@ def extract(
777777
file_path (str, optional): Path to the document file to be processed. Must be provided if `classification_result` is not provided.
778778
project_type (ProjectType, optional): Type of the project. Must be provided if `project_name` is provided.
779779
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.
780+
classification_result (ClassificationResult, optional): The classification result obtained from a previous classification step. If provided, `project_name`, `project_type`, `file`, `file_path`, and `document_type_name` must not be provided.
780781
781782
Note:
782783
Either `file` or `file_path` must be provided, but not both.
783784
784785
Returns:
785-
ExtractionResponse: The extraction result containing predicted data.
786+
Union[ExtractionResponse, ExtractionResponseIXP]: The extraction response containing the extracted data.
786787
787788
Examples:
788789
IXP projects:
@@ -1019,7 +1020,12 @@ async def _get_validation_result_async(
10191020
).json()
10201021

10211022
def _wait_for_create_validation_action(
1022-
self, project_id: str, tag: str, document_type_id: str, operation_id: str
1023+
self,
1024+
project_id: str,
1025+
project_type: ProjectType,
1026+
tag: str,
1027+
document_type_id: str,
1028+
operation_id: str,
10231029
) -> ValidationAction:
10241030
def result_getter() -> Tuple[Any, Optional[Any], Optional[Any]]:
10251031
result = self._get_validation_result(
@@ -1041,13 +1047,19 @@ def result_getter() -> Tuple[Any, Optional[Any], Optional[Any]]:
10411047
)
10421048

10431049
response["projectId"] = project_id
1050+
response["projectType"] = project_type
10441051
response["tag"] = tag
10451052
response["documentTypeId"] = document_type_id
10461053
response["operationId"] = operation_id
10471054
return ValidationAction.model_validate(response)
10481055

10491056
async def _wait_for_create_validation_action_async(
1050-
self, project_id: str, tag: str, document_type_id: str, operation_id: str
1057+
self,
1058+
project_id: str,
1059+
project_type: ProjectType,
1060+
tag: str,
1061+
document_type_id: str,
1062+
operation_id: str,
10511063
) -> ValidationAction:
10521064
async def result_getter_async() -> Tuple[Any, Optional[Any], Optional[Any]]:
10531065
result = await self._get_validation_result_async(
@@ -1069,13 +1081,14 @@ async def result_getter_async() -> Tuple[Any, Optional[Any], Optional[Any]]:
10691081
)
10701082

10711083
response["projectId"] = project_id
1084+
response["projectType"] = project_type
10721085
response["tag"] = tag
10731086
response["documentTypeId"] = document_type_id
10741087
response["operationId"] = operation_id
10751088
return ValidationAction.model_validate(response)
10761089

1077-
@traced(name="documents_create_validation_action", run_type="uipath")
1078-
def create_validation_action(
1090+
@traced(name="documents_create_validate_extraction_action", run_type="uipath")
1091+
def create_validate_extraction_action(
10791092
self,
10801093
action_title: str,
10811094
action_priority: ActionPriority,
@@ -1085,7 +1098,7 @@ def create_validation_action(
10851098
storage_bucket_directory_path: str,
10861099
extraction_response: ExtractionResponse,
10871100
) -> ValidationAction:
1088-
"""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).
1101+
"""Create a validate extraction 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).
10891102
10901103
Args:
10911104
action_title (str): Title of the action.
@@ -1101,12 +1114,12 @@ def create_validation_action(
11011114
11021115
Examples:
11031116
```python
1104-
validation_action = service.create_validation_action(
1117+
validation_action = service.create_validate_extraction_action(
11051118
action_title="Test Validation Action",
11061119
action_priority=ActionPriority.MEDIUM,
11071120
action_catalog="default_du_actions",
11081121
action_folder="Shared",
1109-
storage_bucket_name="TestBucket",
1122+
storage_bucket_name="du_storage_bucket",
11101123
storage_bucket_directory_path="TestDirectory",
11111124
extraction_response=extraction_response,
11121125
)
@@ -1127,13 +1140,14 @@ def create_validation_action(
11271140

11281141
return self._wait_for_create_validation_action(
11291142
project_id=extraction_response.project_id,
1143+
project_type=extraction_response.project_type,
11301144
tag=extraction_response.tag,
11311145
document_type_id=extraction_response.document_type_id,
11321146
operation_id=operation_id,
11331147
)
11341148

1135-
@traced(name="documents_create_validation_action_async", run_type="uipath")
1136-
async def create_validation_action_async(
1149+
@traced(name="documents_create_validate_extraction_action_async", run_type="uipath")
1150+
async def create_validate_extraction_action_async(
11371151
self,
11381152
action_title: str,
11391153
action_priority: ActionPriority,
@@ -1143,7 +1157,7 @@ async def create_validation_action_async(
11431157
storage_bucket_directory_path: str,
11441158
extraction_response: ExtractionResponse,
11451159
) -> ValidationAction:
1146-
"""Asynchronous version of the [`create_validation_action`][uipath._services.documents_service.DocumentsService.create_validation_action] method."""
1160+
"""Asynchronous version of the [`create_validation_action`][uipath._services.documents_service.DocumentsService.create_validate_extraction_action] method."""
11471161
operation_id = await self._start_validation_async(
11481162
project_id=extraction_response.project_id,
11491163
tag=extraction_response.tag,
@@ -1159,29 +1173,30 @@ async def create_validation_action_async(
11591173

11601174
return await self._wait_for_create_validation_action_async(
11611175
project_id=extraction_response.project_id,
1176+
project_type=extraction_response.project_type,
11621177
tag=extraction_response.tag,
11631178
document_type_id=extraction_response.document_type_id,
11641179
operation_id=operation_id,
11651180
)
11661181

1167-
@traced(name="documents_get_validation_result", run_type="uipath")
1168-
def get_validation_result(
1182+
@traced(name="documents_get_validate_extraction_result", run_type="uipath")
1183+
def get_validate_extraction_result(
11691184
self, validation_action: ValidationAction
1170-
) -> ValidatedResult:
1171-
"""Get the result of a validation action.
1185+
) -> Union[ExtractionResponse, ExtractionResponseIXP]:
1186+
"""Get the result of a validate extraction action.
11721187
11731188
Note:
11741189
This method will block until the validation action is completed, meaning the user has completed the validation in UiPath Action Center.
11751190
11761191
Args:
1177-
validation_action (ValidationAction): The validation action to get the result for, typically obtained from the [`create_validation_action`][uipath._services.documents_service.DocumentsService.create_validation_action] method.
1192+
validation_action (ValidationAction): The validation action to get the result for, typically obtained from the [`create_validate_extraction_action`][uipath._services.documents_service.DocumentsService.create_validate_extraction_action] method.
11781193
11791194
Returns:
1180-
ValidatedResult: The result of the validation action.
1195+
Union[ExtractionResponse, ExtractionResponseIXP]: The validated extraction response.
11811196
11821197
Examples:
11831198
```python
1184-
validated_result = service.get_validation_result(validation_action)
1199+
validated_result = service.get_validate_extraction_result(validate_extraction_action)
11851200
```
11861201
"""
11871202

@@ -1192,25 +1207,29 @@ def result_getter() -> Tuple[str, None, Any]:
11921207
document_type_id=validation_action.document_type_id,
11931208
operation_id=validation_action.operation_id,
11941209
)
1195-
return (
1196-
result["result"]["actionStatus"],
1197-
None,
1198-
result["result"].get("validatedExtractionResults", None),
1199-
)
1210+
return (result["result"]["actionStatus"], None, result["result"])
12001211

12011212
response = self._wait_for_operation(
12021213
result_getter=result_getter,
12031214
wait_statuses=["Unassigned", "Pending"],
12041215
success_status="Completed",
12051216
)
1217+
response["extractionResult"] = response.pop("validatedExtractionResults")
1218+
response["projectId"] = validation_action.project_id
1219+
response["tag"] = validation_action.tag
1220+
response["documentTypeId"] = validation_action.document_type_id
1221+
response["projectType"] = validation_action.project_type
12061222

1207-
return ValidatedResult.model_validate(response)
1223+
if validation_action.project_type == ProjectType.IXP:
1224+
return ExtractionResponseIXP.model_validate(response)
12081225

1209-
@traced(name="documents_get_validation_result_async", run_type="uipath")
1210-
async def get_validation_result_async(
1226+
return ExtractionResponse.model_validate(response)
1227+
1228+
@traced(name="documents_get_validate_extraction_result_async", run_type="uipath")
1229+
async def get_validate_extraction_result_async(
12111230
self, validation_action: ValidationAction
1212-
) -> ValidatedResult:
1213-
"""Asynchronous version of the [`get_validation_result`][uipath._services.documents_service.DocumentsService.get_validation_result] method."""
1231+
) -> Union[ExtractionResponse, ExtractionResponseIXP]:
1232+
"""Asynchronous version of the [`get_validation_result`][uipath._services.documents_service.DocumentsService.get_validate_extraction_result] method."""
12141233

12151234
async def result_getter() -> Tuple[str, None, Any]:
12161235
result = await self._get_validation_result_async(
@@ -1219,16 +1238,20 @@ async def result_getter() -> Tuple[str, None, Any]:
12191238
document_type_id=validation_action.document_type_id,
12201239
operation_id=validation_action.operation_id,
12211240
)
1222-
return (
1223-
result["result"]["actionStatus"],
1224-
None,
1225-
result["result"].get("validatedExtractionResults", None),
1226-
)
1241+
return (result["result"]["actionStatus"], None, result["result"])
12271242

12281243
response = await self._wait_for_operation_async(
12291244
result_getter=result_getter,
12301245
wait_statuses=["Unassigned", "Pending"],
12311246
success_status="Completed",
12321247
)
1248+
response["extractionResult"] = response.pop("validatedExtractionResults")
1249+
response["projectId"] = validation_action.project_id
1250+
response["tag"] = validation_action.tag
1251+
response["documentTypeId"] = validation_action.document_type_id
1252+
response["projectType"] = validation_action.project_type
1253+
1254+
if validation_action.project_type == ProjectType.IXP:
1255+
return ExtractionResponseIXP.model_validate(response)
12331256

1234-
return ValidatedResult.model_validate(response)
1257+
return ExtractionResponse.model_validate(response)

src/uipath/models/documents.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from enum import Enum
2-
from typing import List, Optional
2+
from typing import IO, List, Optional, Union
33

44
from pydantic import BaseModel, ConfigDict, Field
55

6+
FileContent = Union[IO[bytes], bytes, str]
7+
68

79
class FieldType(str, Enum):
810
TEXT = "Text"
@@ -98,6 +100,7 @@ class ExtractionResponse(BaseModel):
98100

99101
extraction_result: ExtractionResult = Field(alias="extractionResult")
100102
project_id: str = Field(alias="projectId")
103+
project_type: ProjectType = Field(alias="projectType")
101104
tag: str
102105
document_type_id: str = Field(alias="documentTypeId")
103106

@@ -131,28 +134,12 @@ class ValidationAction(BaseModel):
131134
action_data: dict = Field(alias="actionData") # type: ignore
132135
action_status: str = Field(alias="actionStatus")
133136
project_id: str = Field(alias="projectId")
137+
project_type: ProjectType = Field(alias="projectType")
134138
tag: str
135139
document_type_id: str = Field(alias="documentTypeId")
136140
operation_id: str = Field(alias="operationId")
137141

138142

139-
class ValidatedResult(BaseModel):
140-
"""A model representing the result of a validation action.
141-
142-
Attributes:
143-
document_id (str): The ID of the validated document.
144-
results_document (dict): The validated results document.
145-
"""
146-
147-
model_config = ConfigDict(
148-
serialize_by_alias=True,
149-
validate_by_alias=True,
150-
)
151-
152-
document_id: str = Field(alias="DocumentId")
153-
results_document: dict = Field(alias="ResultsDocument") # type: ignore
154-
155-
156143
class Reference(BaseModel):
157144
model_config = ConfigDict(
158145
serialize_by_alias=True,

0 commit comments

Comments
 (0)