uapi-sdk-python 0.1.16__tar.gz → 0.1.17__tar.gz
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.
- {uapi_sdk_python-0.1.16 → uapi_sdk_python-0.1.17}/PKG-INFO +1 -1
- {uapi_sdk_python-0.1.16 → uapi_sdk_python-0.1.17}/pyproject.toml +1 -1
- {uapi_sdk_python-0.1.16 → uapi_sdk_python-0.1.17}/uapi/client.py +69 -29
- {uapi_sdk_python-0.1.16 → uapi_sdk_python-0.1.17}/uapi_sdk_python.egg-info/PKG-INFO +1 -1
- {uapi_sdk_python-0.1.16 → uapi_sdk_python-0.1.17}/README.md +0 -0
- {uapi_sdk_python-0.1.16 → uapi_sdk_python-0.1.17}/setup.cfg +0 -0
- {uapi_sdk_python-0.1.16 → uapi_sdk_python-0.1.17}/tests/test_client.py +0 -0
- {uapi_sdk_python-0.1.16 → uapi_sdk_python-0.1.17}/uapi/__init__.py +0 -0
- {uapi_sdk_python-0.1.16 → uapi_sdk_python-0.1.17}/uapi/errors.py +0 -0
- {uapi_sdk_python-0.1.16 → uapi_sdk_python-0.1.17}/uapi_sdk_python.egg-info/SOURCES.txt +0 -0
- {uapi_sdk_python-0.1.16 → uapi_sdk_python-0.1.17}/uapi_sdk_python.egg-info/dependency_links.txt +0 -0
- {uapi_sdk_python-0.1.16 → uapi_sdk_python-0.1.17}/uapi_sdk_python.egg-info/requires.txt +0 -0
- {uapi_sdk_python-0.1.16 → uapi_sdk_python-0.1.17}/uapi_sdk_python.egg-info/top_level.txt +0 -0
|
@@ -3,6 +3,7 @@ from dataclasses import dataclass
|
|
|
3
3
|
from typing import Any, Dict, Optional
|
|
4
4
|
import httpx
|
|
5
5
|
import time
|
|
6
|
+
from pathlib import Path
|
|
6
7
|
|
|
7
8
|
from .errors import *
|
|
8
9
|
# internal models live under ./internal (generated by openapi-generator-cli)
|
|
@@ -37,6 +38,31 @@ def _coerce_optional_bool(value: Any) -> Optional[bool]:
|
|
|
37
38
|
return bool(value)
|
|
38
39
|
return bool(value)
|
|
39
40
|
|
|
41
|
+
|
|
42
|
+
def _stringify_form_value(value: Any) -> str:
|
|
43
|
+
if isinstance(value, bool):
|
|
44
|
+
return "true" if value else "false"
|
|
45
|
+
return str(value)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _prepare_file_value(value: Any):
|
|
49
|
+
if isinstance(value, (str, Path)):
|
|
50
|
+
path = Path(value)
|
|
51
|
+
if not path.is_file():
|
|
52
|
+
raise FileNotFoundError(f"File not found: {path}")
|
|
53
|
+
return (path.name, path.read_bytes())
|
|
54
|
+
if isinstance(value, (bytes, bytearray)):
|
|
55
|
+
return ("upload.bin", bytes(value))
|
|
56
|
+
if isinstance(value, tuple):
|
|
57
|
+
return value
|
|
58
|
+
if hasattr(value, "read"):
|
|
59
|
+
content = value.read()
|
|
60
|
+
if isinstance(content, str):
|
|
61
|
+
content = content.encode("utf-8")
|
|
62
|
+
file_name = Path(getattr(value, "name", "upload.bin")).name
|
|
63
|
+
return (file_name or "upload.bin", content)
|
|
64
|
+
raise TypeError(f"Unsupported multipart file value: {type(value)!r}")
|
|
65
|
+
|
|
40
66
|
class _HTTP:
|
|
41
67
|
def __init__(self, cfg: _Config):
|
|
42
68
|
self._cfg = cfg
|
|
@@ -62,6 +88,8 @@ class _HTTP:
|
|
|
62
88
|
*,
|
|
63
89
|
params: Dict[str, Any] | None = None,
|
|
64
90
|
json: Any | None = None,
|
|
91
|
+
data: Dict[str, Any] | None = None,
|
|
92
|
+
files: Dict[str, Any] | None = None,
|
|
65
93
|
headers: Dict[str, str] | None = None,
|
|
66
94
|
disable_cache: bool | None = None,
|
|
67
95
|
):
|
|
@@ -70,7 +98,7 @@ class _HTTP:
|
|
|
70
98
|
if self._cfg.token:
|
|
71
99
|
headers["Authorization"] = f"Bearer {self._cfg.token}"
|
|
72
100
|
query = self._apply_cache_control(method, params, disable_cache)
|
|
73
|
-
r = self._client.request(method, url, params=query, json=json, headers=headers)
|
|
101
|
+
r = self._client.request(method, url, params=query, json=json, data=data, files=files, headers=headers)
|
|
74
102
|
if r.status_code >= 400:
|
|
75
103
|
err = map_error(r)
|
|
76
104
|
self.last_response_meta = err.meta
|
|
@@ -842,7 +870,8 @@ class _ImageApi:
|
|
|
842
870
|
- **500 Internal Server Error**: 如果在压缩过程中服务器发生内部错误,会返回此状态码。
|
|
843
871
|
"""
|
|
844
872
|
params = {}
|
|
845
|
-
|
|
873
|
+
data = {}
|
|
874
|
+
files = {}
|
|
846
875
|
|
|
847
876
|
if "query" == "query" and "level" in kwargs:
|
|
848
877
|
params["level"] = kwargs["level"]
|
|
@@ -854,7 +883,7 @@ class _ImageApi:
|
|
|
854
883
|
params["_t"] = kwargs["_t"]
|
|
855
884
|
|
|
856
885
|
if "file" in kwargs:
|
|
857
|
-
|
|
886
|
+
files["file"] = _prepare_file_value(kwargs["file"])
|
|
858
887
|
|
|
859
888
|
disable_cache = kwargs.get("disable_cache")
|
|
860
889
|
if disable_cache is None and "disableCache" in kwargs:
|
|
@@ -865,7 +894,8 @@ class _ImageApi:
|
|
|
865
894
|
"POST",
|
|
866
895
|
path,
|
|
867
896
|
params=params,
|
|
868
|
-
|
|
897
|
+
data=data or None,
|
|
898
|
+
files=files or None,
|
|
869
899
|
disable_cache=_coerce_optional_bool(disable_cache),
|
|
870
900
|
)
|
|
871
901
|
|
|
@@ -884,7 +914,8 @@ class _ImageApi:
|
|
|
884
914
|
- **网络资源获取**:当您选择传递图片链接时,服务端会自动尝试获取该资源。请确保您提供的图片链接是公网直接可访问的,且不需要任何形式的登录鉴权。
|
|
885
915
|
"""
|
|
886
916
|
params = {}
|
|
887
|
-
|
|
917
|
+
data = {}
|
|
918
|
+
files = {}
|
|
888
919
|
|
|
889
920
|
if "query" == "query" and "width" in kwargs:
|
|
890
921
|
params["width"] = kwargs["width"]
|
|
@@ -914,10 +945,10 @@ class _ImageApi:
|
|
|
914
945
|
params["_t"] = kwargs["_t"]
|
|
915
946
|
|
|
916
947
|
if "file" in kwargs:
|
|
917
|
-
|
|
948
|
+
files["file"] = _prepare_file_value(kwargs["file"])
|
|
918
949
|
|
|
919
950
|
if "url" in kwargs:
|
|
920
|
-
|
|
951
|
+
data["url"] = _stringify_form_value(kwargs["url"])
|
|
921
952
|
|
|
922
953
|
disable_cache = kwargs.get("disable_cache")
|
|
923
954
|
if disable_cache is None and "disableCache" in kwargs:
|
|
@@ -928,7 +959,8 @@ class _ImageApi:
|
|
|
928
959
|
"POST",
|
|
929
960
|
path,
|
|
930
961
|
params=params,
|
|
931
|
-
|
|
962
|
+
data=data or None,
|
|
963
|
+
files=files or None,
|
|
932
964
|
disable_cache=_coerce_optional_bool(disable_cache),
|
|
933
965
|
)
|
|
934
966
|
|
|
@@ -982,19 +1014,20 @@ class _ImageApi:
|
|
|
982
1014
|
- **背景颜色**:同样支持 `bg_color` 表单字段来控制GIF背景。
|
|
983
1015
|
"""
|
|
984
1016
|
params = {}
|
|
985
|
-
|
|
1017
|
+
data = {}
|
|
1018
|
+
files = {}
|
|
986
1019
|
|
|
987
1020
|
if "_t" in kwargs:
|
|
988
1021
|
params["_t"] = kwargs["_t"]
|
|
989
1022
|
|
|
990
1023
|
if "bg_color" in kwargs:
|
|
991
|
-
|
|
1024
|
+
data["bg_color"] = _stringify_form_value(kwargs["bg_color"])
|
|
992
1025
|
|
|
993
1026
|
if "file" in kwargs:
|
|
994
|
-
|
|
1027
|
+
files["file"] = _prepare_file_value(kwargs["file"])
|
|
995
1028
|
|
|
996
1029
|
if "image_url" in kwargs:
|
|
997
|
-
|
|
1030
|
+
data["image_url"] = _stringify_form_value(kwargs["image_url"])
|
|
998
1031
|
|
|
999
1032
|
disable_cache = kwargs.get("disable_cache")
|
|
1000
1033
|
if disable_cache is None and "disableCache" in kwargs:
|
|
@@ -1005,7 +1038,8 @@ class _ImageApi:
|
|
|
1005
1038
|
"POST",
|
|
1006
1039
|
path,
|
|
1007
1040
|
params=params,
|
|
1008
|
-
|
|
1041
|
+
data=data or None,
|
|
1042
|
+
files=files or None,
|
|
1009
1043
|
disable_cache=_coerce_optional_bool(disable_cache),
|
|
1010
1044
|
)
|
|
1011
1045
|
|
|
@@ -1033,16 +1067,17 @@ class _ImageApi:
|
|
|
1033
1067
|
- **inference_time_ms**: 模型推理耗时,单位毫秒
|
|
1034
1068
|
"""
|
|
1035
1069
|
params = {}
|
|
1036
|
-
|
|
1070
|
+
data = {}
|
|
1071
|
+
files = {}
|
|
1037
1072
|
|
|
1038
1073
|
if "_t" in kwargs:
|
|
1039
1074
|
params["_t"] = kwargs["_t"]
|
|
1040
1075
|
|
|
1041
1076
|
if "file" in kwargs:
|
|
1042
|
-
|
|
1077
|
+
files["file"] = _prepare_file_value(kwargs["file"])
|
|
1043
1078
|
|
|
1044
1079
|
if "url" in kwargs:
|
|
1045
|
-
|
|
1080
|
+
data["url"] = _stringify_form_value(kwargs["url"])
|
|
1046
1081
|
|
|
1047
1082
|
disable_cache = kwargs.get("disable_cache")
|
|
1048
1083
|
if disable_cache is None and "disableCache" in kwargs:
|
|
@@ -1053,7 +1088,8 @@ class _ImageApi:
|
|
|
1053
1088
|
"POST",
|
|
1054
1089
|
path,
|
|
1055
1090
|
params=params,
|
|
1056
|
-
|
|
1091
|
+
data=data or None,
|
|
1092
|
+
files=files or None,
|
|
1057
1093
|
disable_cache=_coerce_optional_bool(disable_cache),
|
|
1058
1094
|
)
|
|
1059
1095
|
|
|
@@ -1071,31 +1107,32 @@ class _ImageApi:
|
|
|
1071
1107
|
- **灵活的输入与请求要求**:接口支持 `file`、`url` 或 `image_base64` 三种方式输入。请确保请求格式为 `multipart/form-data`,且图片链接在公网可直接访问。
|
|
1072
1108
|
"""
|
|
1073
1109
|
params = {}
|
|
1074
|
-
|
|
1110
|
+
data = {}
|
|
1111
|
+
files = {}
|
|
1075
1112
|
|
|
1076
1113
|
if "_t" in kwargs:
|
|
1077
1114
|
params["_t"] = kwargs["_t"]
|
|
1078
1115
|
|
|
1079
1116
|
if "enable_cls" in kwargs:
|
|
1080
|
-
|
|
1117
|
+
data["enable_cls"] = _stringify_form_value(kwargs["enable_cls"])
|
|
1081
1118
|
|
|
1082
1119
|
if "file" in kwargs:
|
|
1083
|
-
|
|
1120
|
+
files["file"] = _prepare_file_value(kwargs["file"])
|
|
1084
1121
|
|
|
1085
1122
|
if "image_base64" in kwargs:
|
|
1086
|
-
|
|
1123
|
+
data["image_base64"] = _stringify_form_value(kwargs["image_base64"])
|
|
1087
1124
|
|
|
1088
1125
|
if "image_name" in kwargs:
|
|
1089
|
-
|
|
1126
|
+
data["image_name"] = _stringify_form_value(kwargs["image_name"])
|
|
1090
1127
|
|
|
1091
1128
|
if "need_location" in kwargs:
|
|
1092
|
-
|
|
1129
|
+
data["need_location"] = _stringify_form_value(kwargs["need_location"])
|
|
1093
1130
|
|
|
1094
1131
|
if "return_markdown" in kwargs:
|
|
1095
|
-
|
|
1132
|
+
data["return_markdown"] = _stringify_form_value(kwargs["return_markdown"])
|
|
1096
1133
|
|
|
1097
1134
|
if "url" in kwargs:
|
|
1098
|
-
|
|
1135
|
+
data["url"] = _stringify_form_value(kwargs["url"])
|
|
1099
1136
|
|
|
1100
1137
|
disable_cache = kwargs.get("disable_cache")
|
|
1101
1138
|
if disable_cache is None and "disableCache" in kwargs:
|
|
@@ -1106,7 +1143,8 @@ class _ImageApi:
|
|
|
1106
1143
|
"POST",
|
|
1107
1144
|
path,
|
|
1108
1145
|
params=params,
|
|
1109
|
-
|
|
1146
|
+
data=data or None,
|
|
1147
|
+
files=files or None,
|
|
1110
1148
|
disable_cache=_coerce_optional_bool(disable_cache),
|
|
1111
1149
|
)
|
|
1112
1150
|
|
|
@@ -1152,7 +1190,8 @@ class _ImageApi:
|
|
|
1152
1190
|
上传一个 SVG 文件,并指定目标格式(如 PNG、JPEG 等),接口将返回转换后的图像。你还可以调整输出图像的尺寸和(对于JPEG)压缩质量,以满足不同场景的需求。
|
|
1153
1191
|
"""
|
|
1154
1192
|
params = {}
|
|
1155
|
-
|
|
1193
|
+
data = {}
|
|
1194
|
+
files = {}
|
|
1156
1195
|
|
|
1157
1196
|
if "query" == "query" and "format" in kwargs:
|
|
1158
1197
|
params["format"] = kwargs["format"]
|
|
@@ -1170,7 +1209,7 @@ class _ImageApi:
|
|
|
1170
1209
|
params["_t"] = kwargs["_t"]
|
|
1171
1210
|
|
|
1172
1211
|
if "file" in kwargs:
|
|
1173
|
-
|
|
1212
|
+
files["file"] = _prepare_file_value(kwargs["file"])
|
|
1174
1213
|
|
|
1175
1214
|
disable_cache = kwargs.get("disable_cache")
|
|
1176
1215
|
if disable_cache is None and "disableCache" in kwargs:
|
|
@@ -1181,7 +1220,8 @@ class _ImageApi:
|
|
|
1181
1220
|
"POST",
|
|
1182
1221
|
path,
|
|
1183
1222
|
params=params,
|
|
1184
|
-
|
|
1223
|
+
data=data or None,
|
|
1224
|
+
files=files or None,
|
|
1185
1225
|
disable_cache=_coerce_optional_bool(disable_cache),
|
|
1186
1226
|
)
|
|
1187
1227
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{uapi_sdk_python-0.1.16 → uapi_sdk_python-0.1.17}/uapi_sdk_python.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|