xinference-client 4.3.0__tar.gz → 5.0.0__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.
Files changed (27) hide show
  1. {xinference_client-4.3.0/xinference_client.egg-info → xinference_client-5.0.0}/PKG-INFO +1 -1
  2. {xinference_client-4.3.0 → xinference_client-5.0.0}/xinference_client/_compat.py +4 -0
  3. {xinference_client-4.3.0 → xinference_client-5.0.0}/xinference_client/_version.py +3 -3
  4. {xinference_client-4.3.0 → xinference_client-5.0.0}/xinference_client/client/common.py +20 -1
  5. {xinference_client-4.3.0 → xinference_client-5.0.0}/xinference_client/client/restful/async_restful_client.py +107 -3
  6. {xinference_client-4.3.0 → xinference_client-5.0.0}/xinference_client/client/restful/restful_client.py +106 -4
  7. {xinference_client-4.3.0 → xinference_client-5.0.0/xinference_client.egg-info}/PKG-INFO +1 -1
  8. {xinference_client-4.3.0 → xinference_client-5.0.0}/LICENSE +0 -0
  9. {xinference_client-4.3.0 → xinference_client-5.0.0}/MANIFEST.in +0 -0
  10. {xinference_client-4.3.0 → xinference_client-5.0.0}/README.md +0 -0
  11. {xinference_client-4.3.0 → xinference_client-5.0.0}/pyproject.toml +0 -0
  12. {xinference_client-4.3.0 → xinference_client-5.0.0}/setup.cfg +0 -0
  13. {xinference_client-4.3.0 → xinference_client-5.0.0}/setup.py +0 -0
  14. {xinference_client-4.3.0 → xinference_client-5.0.0}/tests/test_async_client.py +0 -0
  15. {xinference_client-4.3.0 → xinference_client-5.0.0}/tests/test_async_client_cleanup.py +0 -0
  16. {xinference_client-4.3.0 → xinference_client-5.0.0}/third_party/inference/xinference/thirdparty/matcha/utils/monotonic_align/core.pyx +0 -0
  17. {xinference_client-4.3.0 → xinference_client-5.0.0}/versioneer.py +0 -0
  18. {xinference_client-4.3.0 → xinference_client-5.0.0}/xinference_client/__init__.py +0 -0
  19. {xinference_client-4.3.0 → xinference_client-5.0.0}/xinference_client/client/__init__.py +0 -0
  20. {xinference_client-4.3.0 → xinference_client-5.0.0}/xinference_client/client/restful/__init__.py +0 -0
  21. {xinference_client-4.3.0 → xinference_client-5.0.0}/xinference_client/fields.py +0 -0
  22. {xinference_client-4.3.0 → xinference_client-5.0.0}/xinference_client/types.py +0 -0
  23. {xinference_client-4.3.0 → xinference_client-5.0.0}/xinference_client.egg-info/SOURCES.txt +0 -0
  24. {xinference_client-4.3.0 → xinference_client-5.0.0}/xinference_client.egg-info/dependency_links.txt +0 -0
  25. {xinference_client-4.3.0 → xinference_client-5.0.0}/xinference_client.egg-info/not-zip-safe +0 -0
  26. {xinference_client-4.3.0 → xinference_client-5.0.0}/xinference_client.egg-info/requires.txt +0 -0
  27. {xinference_client-4.3.0 → xinference_client-5.0.0}/xinference_client.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xinference-client
3
- Version: 4.3.0
3
+ Version: 5.0.0
4
4
  Summary: Client for Xinference
5
5
  Home-page: https://github.com/xorbitsai/inference-client
6
6
  Author: Qin Xuye
@@ -24,7 +24,9 @@ if PYDANTIC_V2:
24
24
  BaseModel,
25
25
  Field,
26
26
  Protocol,
27
+ StrictBool,
27
28
  StrictInt,
29
+ StrictStr,
28
30
  ValidationError,
29
31
  create_model,
30
32
  create_model_from_namedtuple,
@@ -42,7 +44,9 @@ else:
42
44
  BaseModel,
43
45
  Field,
44
46
  Protocol,
47
+ StrictBool,
45
48
  StrictInt,
49
+ StrictStr,
46
50
  ValidationError,
47
51
  create_model,
48
52
  create_model_from_namedtuple,
@@ -8,11 +8,11 @@ import json
8
8
 
9
9
  version_json = '''
10
10
  {
11
- "date": "2026-11-26T16:25:20+0800",
11
+ "date": "2026-12-05T23:05:26+0800",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "0fd4fc33a816d81f822532363a2517c0f9b2141c",
15
- "version": "4.3.0"
14
+ "full-revisionid": "6041fccef363516132579047d50b424dca2b7525",
15
+ "version": "5.0.0"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
@@ -15,11 +15,15 @@
15
15
  import base64
16
16
  import json
17
17
  import os
18
- from typing import Any, AsyncIterator, Iterator, Union
18
+ from contextlib import contextmanager
19
+ from pathlib import Path
20
+ from tempfile import NamedTemporaryFile
21
+ from typing import IO, Any, AsyncIterator, Iterator, Union
19
22
 
20
23
  # (connect, read) seconds for fetching an image URL, as used by the server.
21
24
  # The read timeout limits inactivity, not the total download time.
22
25
  IMAGE_DOWNLOAD_TIMEOUT = (10, 30)
26
+ MESH_DOWNLOAD_CHUNK_SIZE = 64 * 1024
23
27
 
24
28
 
25
29
  def normalize_endpoint(endpoint: str) -> str:
@@ -38,6 +42,21 @@ def read_file_input(value: Union[str, bytes]) -> bytes:
38
42
  return value
39
43
 
40
44
 
45
+ @contextmanager
46
+ def mesh_output_file(path: Path) -> Iterator[IO[bytes]]:
47
+ """Publish a downloaded mesh only after its response has been read."""
48
+ temporary = NamedTemporaryFile(
49
+ dir=path.parent, prefix=".xinference-mesh-", suffix=".part", delete=False
50
+ )
51
+ temporary_path = Path(temporary.name)
52
+ try:
53
+ with temporary:
54
+ yield temporary.file
55
+ temporary_path.replace(path)
56
+ finally:
57
+ temporary_path.unlink(missing_ok=True)
58
+
59
+
41
60
  def encode_world_reference(reference: Union[str, bytes], media_type: str) -> str:
42
61
  if isinstance(reference, str) and not os.path.isfile(reference):
43
62
  return reference
@@ -13,6 +13,7 @@
13
13
  # limitations under the License.
14
14
  import asyncio
15
15
  import json
16
+ from pathlib import Path
16
17
  from typing import TYPE_CHECKING, Any, AsyncIterator, Dict, List, Optional, Union
17
18
  from urllib.parse import quote
18
19
 
@@ -20,10 +21,12 @@ import aiohttp
20
21
 
21
22
  from ..common import (
22
23
  IMAGE_DOWNLOAD_TIMEOUT,
24
+ MESH_DOWNLOAD_CHUNK_SIZE,
23
25
  async_streaming_response_iterator,
24
26
  convert_float_to_int_or_str,
25
27
  encode_world_reference,
26
28
  is_http_url,
29
+ mesh_output_file,
27
30
  normalize_endpoint,
28
31
  read_file_input,
29
32
  )
@@ -893,6 +896,97 @@ class AsyncRESTfulVideoModelHandle(AsyncRESTfulModelHandle):
893
896
  return response_data
894
897
 
895
898
 
899
+ class AsyncRESTfulMeshModelHandle(AsyncRESTfulModelHandle):
900
+ async def image_to_mesh(
901
+ self,
902
+ image: Union[str, bytes],
903
+ *,
904
+ seed: Optional[int] = None,
905
+ num_inference_steps: Optional[int] = None,
906
+ textured: bool = False,
907
+ request_id: Optional[str] = None,
908
+ output_path: Optional[Union[str, Path]] = None,
909
+ ) -> Union[bytes, Path]:
910
+ """Generate a GLB from image bytes or a local image path.
911
+
912
+ Return GLB bytes by default. With output_path, download in chunks and
913
+ return the destination path.
914
+ Set textured to generate textures on a model that supports it.
915
+ """
916
+ data = aiohttp.FormData()
917
+ params = _filter_params(
918
+ {
919
+ "model": self._model_uid,
920
+ "seed": seed,
921
+ "num_inference_steps": num_inference_steps,
922
+ "request_id": request_id,
923
+ "textured": "true" if textured else None,
924
+ }
925
+ )
926
+ for key, value in params.items():
927
+ data.add_field(key, str(value))
928
+ data.add_field(
929
+ "image",
930
+ await asyncio.to_thread(read_file_input, image),
931
+ filename="image",
932
+ content_type="application/octet-stream",
933
+ )
934
+ async with self.session.post(
935
+ f"{self._base_url}/v1/meshes/generations",
936
+ data=data,
937
+ headers=self.auth_headers,
938
+ ) as response:
939
+ if response.status != 200:
940
+ raise RuntimeError(
941
+ "Failed to generate the mesh, detail: "
942
+ f"{await _get_error_string(response)}"
943
+ )
944
+ if output_path is None:
945
+ return await response.read()
946
+ destination = Path(output_path)
947
+ with mesh_output_file(destination) as file:
948
+ async for chunk in response.content.iter_chunked(
949
+ MESH_DOWNLOAD_CHUNK_SIZE
950
+ ):
951
+ file.write(chunk)
952
+ return destination
953
+
954
+
955
+ class _AsyncRESTfulDecisionMixin(AsyncRESTfulModelHandle):
956
+ async def decide(
957
+ self,
958
+ state: Union[str, dict, list],
959
+ questions: Dict[str, dict],
960
+ *,
961
+ images: Optional[List[str]] = None,
962
+ **kwargs,
963
+ ) -> dict:
964
+ """Return the answers to named choice, score and noul questions."""
965
+ payload = {
966
+ **kwargs,
967
+ "model": self._model_uid,
968
+ "state": state,
969
+ "questions": questions,
970
+ }
971
+ if images is not None:
972
+ payload["images"] = images
973
+ async with self.session.post(
974
+ f"{self._base_url}/v1/systemone", json=payload, headers=self.auth_headers
975
+ ) as response:
976
+ if response.status != 200:
977
+ raise RuntimeError(
978
+ f"Decision inference failed: {await _get_error_string(response)}"
979
+ )
980
+ return await response.json()
981
+
982
+ async def decision(self, state, questions: dict, **kwargs) -> dict:
983
+ return await self.decide(state, questions, **kwargs)
984
+
985
+
986
+ class AsyncRESTfulDecisionModelHandle(_AsyncRESTfulDecisionMixin):
987
+ pass
988
+
989
+
896
990
  class AsyncRESTfulWorldModelHandle(AsyncRESTfulModelHandle):
897
991
  async def generate(
898
992
  self,
@@ -939,7 +1033,7 @@ class AsyncRESTfulWorldModelHandle(AsyncRESTfulModelHandle):
939
1033
  return response_data
940
1034
 
941
1035
 
942
- class AsyncRESTfulGenerateModelHandle(AsyncRESTfulModelHandle):
1036
+ class AsyncRESTfulGenerateModelHandle(_AsyncRESTfulDecisionMixin):
943
1037
  async def generate(
944
1038
  self,
945
1039
  prompt: str,
@@ -2027,10 +2121,20 @@ class AsyncClient:
2027
2121
  return AsyncRESTfulVideoModelHandle(
2028
2122
  model_uid, self.base_url, auth_headers=self._headers
2029
2123
  )
2124
+ elif desc["model_type"] == "decision":
2125
+ return AsyncRESTfulDecisionModelHandle(
2126
+ model_uid, self.base_url, auth_headers=self._headers
2127
+ )
2030
2128
  elif desc["model_type"] == "world":
2031
2129
  return AsyncRESTfulWorldModelHandle(
2032
2130
  model_uid, self.base_url, auth_headers=self._headers
2033
2131
  )
2132
+ elif desc["model_type"] == "3d":
2133
+ if "image_to_mesh" not in desc["model_ability"]:
2134
+ raise ValueError(f"Unrecognized model ability: {desc['model_ability']}")
2135
+ return AsyncRESTfulMeshModelHandle(
2136
+ model_uid, self.base_url, auth_headers=self._headers
2137
+ )
2034
2138
  elif desc["model_type"] == "flexible":
2035
2139
  return AsyncRESTfulFlexibleModelHandle(
2036
2140
  model_uid, self.base_url, auth_headers=self._headers
@@ -2367,7 +2471,7 @@ class AsyncClient:
2367
2471
  return response_data
2368
2472
 
2369
2473
  async def abort_request(
2370
- self, model_uid: str, request_id: str, block_duration: int = 30
2474
+ self, model_uid: str, request_id: str, block_duration: float = 30
2371
2475
  ):
2372
2476
  """
2373
2477
  Abort a request.
@@ -2380,7 +2484,7 @@ class AsyncClient:
2380
2484
  Model uid.
2381
2485
  request_id: str
2382
2486
  Request id.
2383
- block_duration: int
2487
+ block_duration: float
2384
2488
  The duration to make the request id abort. If set to 0, the abort_request will be immediate, which may
2385
2489
  prevent it from taking effect if it arrives before the request operation.
2386
2490
  Returns
@@ -12,6 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  import json
15
+ from pathlib import Path
15
16
  from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Union
16
17
  from urllib.parse import quote
17
18
 
@@ -19,9 +20,11 @@ import requests
19
20
 
20
21
  from ..common import (
21
22
  IMAGE_DOWNLOAD_TIMEOUT,
23
+ MESH_DOWNLOAD_CHUNK_SIZE,
22
24
  convert_float_to_int_or_str,
23
25
  encode_world_reference,
24
26
  is_http_url,
27
+ mesh_output_file,
25
28
  normalize_endpoint,
26
29
  read_file_input,
27
30
  streaming_response_iterator,
@@ -783,6 +786,86 @@ class RESTfulVideoModelHandle(RESTfulModelHandle):
783
786
  return response_data
784
787
 
785
788
 
789
+ class RESTfulMeshModelHandle(RESTfulModelHandle):
790
+ def image_to_mesh(
791
+ self,
792
+ image: Union[str, bytes],
793
+ *,
794
+ seed: Optional[int] = None,
795
+ num_inference_steps: Optional[int] = None,
796
+ textured: bool = False,
797
+ request_id: Optional[str] = None,
798
+ output_path: Optional[Union[str, Path]] = None,
799
+ ) -> Union[bytes, Path]:
800
+ """Generate a GLB from image bytes or a local image path.
801
+
802
+ Return GLB bytes by default. With output_path, download in chunks and
803
+ return the destination path.
804
+ Set textured to generate textures on a model that supports it.
805
+ """
806
+ with self.session.post(
807
+ f"{self._base_url}/v1/meshes/generations",
808
+ data={
809
+ "model": self._model_uid,
810
+ "seed": seed,
811
+ "num_inference_steps": num_inference_steps,
812
+ "request_id": request_id,
813
+ **({"textured": "true"} if textured else {}),
814
+ },
815
+ files={
816
+ "image": ("image", read_file_input(image), "application/octet-stream")
817
+ },
818
+ headers=self.auth_headers,
819
+ stream=output_path is not None,
820
+ ) as response:
821
+ if response.status_code != 200:
822
+ raise RuntimeError(
823
+ f"Failed to generate the mesh, detail: {_get_error_string(response)}"
824
+ )
825
+ if output_path is None:
826
+ return response.content
827
+ destination = Path(output_path)
828
+ with mesh_output_file(destination) as file:
829
+ for chunk in response.iter_content(chunk_size=MESH_DOWNLOAD_CHUNK_SIZE):
830
+ file.write(chunk)
831
+ return destination
832
+
833
+
834
+ class _RESTfulDecisionMixin(RESTfulModelHandle):
835
+ def decide(
836
+ self,
837
+ state: Union[str, dict, list],
838
+ questions: Dict[str, dict],
839
+ *,
840
+ images: Optional[List[str]] = None,
841
+ **kwargs,
842
+ ) -> dict:
843
+ """Return the answers to named choice, score and noul questions."""
844
+ payload = {
845
+ **kwargs,
846
+ "model": self._model_uid,
847
+ "state": state,
848
+ "questions": questions,
849
+ }
850
+ if images is not None:
851
+ payload["images"] = images
852
+ with self.session.post(
853
+ f"{self._base_url}/v1/systemone", json=payload, headers=self.auth_headers
854
+ ) as response:
855
+ if response.status_code != 200:
856
+ raise RuntimeError(
857
+ f"Decision inference failed: {_get_error_string(response)}"
858
+ )
859
+ return response.json()
860
+
861
+ def decision(self, state, questions: dict, **kwargs) -> dict:
862
+ return self.decide(state, questions, **kwargs)
863
+
864
+
865
+ class RESTfulDecisionModelHandle(_RESTfulDecisionMixin):
866
+ pass
867
+
868
+
786
869
  class RESTfulWorldModelHandle(RESTfulModelHandle):
787
870
  def generate(
788
871
  self,
@@ -824,7 +907,7 @@ class RESTfulWorldModelHandle(RESTfulModelHandle):
824
907
  return response.json()
825
908
 
826
909
 
827
- class RESTfulGenerateModelHandle(RESTfulModelHandle):
910
+ class RESTfulGenerateModelHandle(_RESTfulDecisionMixin):
828
911
  def generate(
829
912
  self,
830
913
  prompt: str,
@@ -1266,8 +1349,15 @@ class Client:
1266
1349
  self._cluster_authed = False
1267
1350
  else:
1268
1351
  if response.status_code != 200:
1352
+ # The server's JSON detail when there is one; otherwise only the
1353
+ # status, because str(HTTPError) includes the URL and any
1354
+ # credentials embedded in it.
1355
+ try:
1356
+ detail = response.json()["detail"]
1357
+ except Exception:
1358
+ detail = f"{response.status_code} {response.reason}".strip()
1269
1359
  raise RuntimeError(
1270
- f"Failed to get cluster information, detail: {response.json()['detail']}"
1360
+ f"Failed to get cluster information, detail: {detail}"
1271
1361
  )
1272
1362
  response_data = response.json()
1273
1363
  self._cluster_authed = bool(response_data["auth"])
@@ -1789,10 +1879,20 @@ class Client:
1789
1879
  return RESTfulVideoModelHandle(
1790
1880
  model_uid, self.base_url, auth_headers=self._headers
1791
1881
  )
1882
+ elif desc["model_type"] == "decision":
1883
+ return RESTfulDecisionModelHandle(
1884
+ model_uid, self.base_url, auth_headers=self._headers
1885
+ )
1792
1886
  elif desc["model_type"] == "world":
1793
1887
  return RESTfulWorldModelHandle(
1794
1888
  model_uid, self.base_url, auth_headers=self._headers
1795
1889
  )
1890
+ elif desc["model_type"] == "3d":
1891
+ if "image_to_mesh" not in desc["model_ability"]:
1892
+ raise ValueError(f"Unrecognized model ability: {desc['model_ability']}")
1893
+ return RESTfulMeshModelHandle(
1894
+ model_uid, self.base_url, auth_headers=self._headers
1895
+ )
1796
1896
  elif desc["model_type"] == "flexible":
1797
1897
  return RESTfulFlexibleModelHandle(
1798
1898
  model_uid, self.base_url, auth_headers=self._headers
@@ -2109,7 +2209,9 @@ class Client:
2109
2209
  response_data = response.json()
2110
2210
  return response_data
2111
2211
 
2112
- def abort_request(self, model_uid: str, request_id: str, block_duration: int = 30):
2212
+ def abort_request(
2213
+ self, model_uid: str, request_id: str, block_duration: float = 30
2214
+ ):
2113
2215
  """
2114
2216
  Abort a request.
2115
2217
  Abort a submitted request. If the request is finished or not found, this method will be a no-op.
@@ -2121,7 +2223,7 @@ class Client:
2121
2223
  Model uid.
2122
2224
  request_id: str
2123
2225
  Request id.
2124
- block_duration: int
2226
+ block_duration: float
2125
2227
  The duration to make the request id abort. If set to 0, the abort_request will be immediate, which may
2126
2228
  prevent it from taking effect if it arrives before the request operation.
2127
2229
  Returns
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xinference-client
3
- Version: 4.3.0
3
+ Version: 5.0.0
4
4
  Summary: Client for Xinference
5
5
  Home-page: https://github.com/xorbitsai/inference-client
6
6
  Author: Qin Xuye