File tree Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Original file line number Diff line number Diff line change 44from typing import Any , List , Optional
55from unstructured_client import utils
66from unstructured_client .models import errors , operations , shared
7+ from unstructured_client .utils ._decorators import suggest_defining_url_if_401 # human code
8+
79
810class General :
911 sdk_configuration : SDKConfiguration
@@ -12,7 +14,7 @@ def __init__(self, sdk_config: SDKConfiguration) -> None:
1214 self .sdk_configuration = sdk_config
1315
1416
15-
17+ @ suggest_defining_url_if_401 # human code
1618 def partition (self , request : Optional [shared .PartitionParameters ], retries : Optional [utils .RetryConfig ] = None ) -> operations .PartitionResponse :
1719 r"""Pipeline 1"""
1820 base_url = utils .template_url (* self .sdk_configuration .get_server_details ())
Original file line number Diff line number Diff line change 66from typing import Callable , Dict , Union
77from unstructured_client import utils
88from unstructured_client .models import shared
9- from unstructured_client .utils ._decorators import clean_server_url
9+ from unstructured_client .utils ._decorators import clean_server_url # human code
1010
1111class UnstructuredClient :
1212 r"""Unstructured Pipeline API: Partition documents with the Unstructured library"""
1313 general : General
1414
1515 sdk_configuration : SDKConfiguration
1616
17- @clean_server_url
17+ @clean_server_url # human code
1818 def __init__ (self ,
1919 api_key_auth : Union [str , Callable [[], str ]],
2020 server : str = None ,
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
33import functools
4- from typing import cast , Callable , Optional
4+ from typing import cast , Callable , TYPE_CHECKING , Optional
55from typing_extensions import ParamSpec
66from urllib .parse import urlparse , urlunparse , ParseResult
7+ import warnings
8+
9+ from unstructured_client .models import errors
10+
11+ if TYPE_CHECKING :
12+ from unstructured_client .general import General
713
814
915_P = ParamSpec ("_P" )
@@ -44,3 +50,18 @@ def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> None:
4450 return func (* args , ** kwargs )
4551
4652 return wrapper
53+
54+
55+ def suggest_defining_url_if_401 (func : Callable [_P , None ]) -> Callable [_P , None ]:
56+
57+ @functools .wraps (func )
58+ def wrapper (* args : _P .args , ** kwargs : _P .kwargs ) -> None :
59+ try :
60+ return func (* args , ** kwargs )
61+ except errors .SDKError :
62+ general_obj : General = args [0 ]
63+ if not general_obj .sdk_configuration .server_url :
64+ warnings .warn ("If intending to use the paid API, please define `server_url` in your request." )
65+ return func (* args , ** kwargs )
66+
67+ return wrapper
You can’t perform that action at this time.
0 commit comments