Skip to content

Commit 2089072

Browse files
authored
fix: Update calls to unstructured-client for forward compatibility (#33)
* fix: Update calls to unstructured-client for forward compatibility Per the usage example [here](https://docs.unstructured.io/api-reference/api-services/sdk-python#basics), the call to `sdk.general.partition` expects a `shared.PartitionRequest` object. In older versions of the client, this object was not needed, but the call has stayed backwards compatible. The next version of the client (0.26.0) is going to lose support for directly passing `PartitionParameters`. * Reorder new import * Add a changelog note * Adjust order of imports * Sync the new version * Add missing import for PartitionRequest
1 parent dfdd4d7 commit 2089072

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 0.0.6
2+
3+
### Enhancements
4+
5+
### Fixes
6+
7+
* **unstructured-client compatibility fix** Update the calls to `unstructured_client.general.partion` to avoid a breaking change in the newest version.
8+
19
## 0.0.5
210

311
### Enhancements

requirements/remote/client.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
-r ../common/base.in
22

3-
unstructured-client
3+
unstructured-client >= 0.23.0

unstructured_ingest/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.5" # pragma: no cover
1+
__version__ = "0.0.6" # pragma: no cover

unstructured_ingest/v2/processes/chunker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def run(self, elements_filepath: Path, **kwargs: Any) -> list[dict]:
112112
@requires_dependencies(dependencies=["unstructured_client"], extras="remote")
113113
async def run_async(self, elements_filepath: Path, **kwargs: Any) -> list[dict]:
114114
from unstructured_client import UnstructuredClient
115+
from unstructured_client.models.operations import PartitionRequest
115116
from unstructured_client.models.shared import Files, PartitionParameters
116117

117118
client = UnstructuredClient(
@@ -137,7 +138,8 @@ async def run_async(self, elements_filepath: Path, **kwargs: Any) -> list[dict]:
137138
)
138139
filtered_partition_request["files"] = files
139140
partition_params = PartitionParameters(**filtered_partition_request)
140-
resp = client.general.partition(partition_params)
141+
partition_request_obj = PartitionRequest(partition_params)
142+
resp = client.general.partition(partition_request_obj)
141143
elements = resp.elements or []
142144
elements = assign_and_map_hash_ids(elements=elements)
143145
return elements

unstructured_ingest/v2/processes/partitioner.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
if TYPE_CHECKING:
1515
from unstructured_client import UnstructuredClient
16+
from unstructured_client.models.operations import PartitionRequest
1617
from unstructured_client.models.shared import PartitionParameters
1718

1819

@@ -153,7 +154,7 @@ class FileDataSourceMetadata(DataSourceMetadata):
153154
)
154155
return self.postprocess(elements=elements_to_dicts(elements))
155156

156-
async def call_api(self, client: "UnstructuredClient", request: "PartitionParameters"):
157+
async def call_api(self, client: "UnstructuredClient", request: "PartitionRequest"):
157158
# TODO when client supports async, run without using run_in_executor
158159
# isolate the IO heavy call
159160
loop = asyncio.get_event_loop()
@@ -189,14 +190,16 @@ async def partition_via_api(
189190
self, filename: Path, metadata: Optional[dict] = None, **kwargs
190191
) -> list[dict]:
191192
from unstructured_client import UnstructuredClient
193+
from unstructured_client.models.operations import PartitionRequest
192194

193195
logger.debug(f"partitioning file {filename} with metadata: {metadata}")
194196
client = UnstructuredClient(
195197
server_url=self.config.partition_endpoint,
196198
api_key_auth=self.config.api_key.get_secret_value(),
197199
)
198200
partition_params = self.create_partition_parameters(filename=filename)
199-
resp = await self.call_api(client=client, request=partition_params)
201+
partition_request = PartitionRequest(partition_params)
202+
resp = await self.call_api(client=client, request=partition_request)
200203
elements = resp.elements or []
201204
# Append the data source metadata the auto partition does for you
202205
for element in elements:

0 commit comments

Comments
 (0)