diff --git a/lib/aryn-sdk/aryn_sdk/partition/partition.py b/lib/aryn-sdk/aryn_sdk/partition/partition.py index 924bbf35b..f39cc9663 100644 --- a/lib/aryn-sdk/aryn_sdk/partition/partition.py +++ b/lib/aryn-sdk/aryn_sdk/partition/partition.py @@ -23,6 +23,7 @@ g_version = "0.1.11" + class PartitionError(Exception): def __init__(self, message: str, status_code: int) -> None: super().__init__(message) @@ -377,12 +378,12 @@ def partition_file_async_submit( if async_submit_url: docparse_url = async_submit_url elif not aps_url and not docparse_url: - docparse_url = _convert_sync_to_async_url(ARYN_DOCPARSE_URL, prefix="/submit", include_rest_of_url=True) + docparse_url = _convert_sync_to_async_url(ARYN_DOCPARSE_URL, "/submit", False) else: if aps_url: - aps_url = _convert_sync_to_async_url(aps_url, prefix="/submit", include_rest_of_url=True) + aps_url = _convert_sync_to_async_url(aps_url, "/submit", False) if docparse_url: - docparse_url = _convert_sync_to_async_url(docparse_url, prefix="/submit", include_rest_of_url=True) + docparse_url = _convert_sync_to_async_url(docparse_url, "/submit", False) return _partition_file_inner( file=file, @@ -405,13 +406,16 @@ def partition_file_async_submit( ) -def _convert_sync_to_async_url(url: str, *, prefix: str, include_rest_of_url: bool = False) -> str: +def _convert_sync_to_async_url(url: str, prefix: str, truncate: bool) -> str: parsed_url = urlparse(url) assert parsed_url.path.startswith("/v1/") if parsed_url.path.startswith("/v1/async/submit"): return url ary = list(parsed_url) - ary[2] = f"/v1/async{prefix}{parsed_url.path[3:] if include_rest_of_url else ''}" # path + if truncate: + ary[2] = f"/v1/async{prefix}" # path + else: + ary[2] = f"/v1/async{prefix}{parsed_url.path[3:]}" # path return urlunparse(ary) @@ -437,7 +441,7 @@ def partition_file_async_result( `partition_file` had the partitioning been done synchronously. """ if not async_result_url: - async_result_url = _convert_sync_to_async_url(ARYN_DOCPARSE_URL, prefix="/result") + async_result_url = _convert_sync_to_async_url(ARYN_DOCPARSE_URL, "/result", True) aryn_config = _process_config(aryn_api_key, aryn_config) @@ -475,7 +479,7 @@ def partition_file_async_cancel( For an example of usage see README.md """ if not async_cancel_url: - async_cancel_url = _convert_sync_to_async_url(ARYN_DOCPARSE_URL, prefix="/cancel") + async_cancel_url = _convert_sync_to_async_url(ARYN_DOCPARSE_URL, "/cancel", True) aryn_config = _process_config(aryn_api_key, aryn_config) @@ -518,7 +522,7 @@ def partition_file_async_list( } """ if not async_list_url: - async_list_url = _convert_sync_to_async_url(ARYN_DOCPARSE_URL, prefix="/list") + async_list_url = _convert_sync_to_async_url(ARYN_DOCPARSE_URL, "/list", True) aryn_config = _process_config(aryn_api_key, aryn_config)