xinference-client 4.2.0__tar.gz → 4.3.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.2.0/xinference_client.egg-info → xinference_client-4.3.0}/PKG-INFO +1 -1
  2. {xinference_client-4.2.0 → xinference_client-4.3.0}/xinference_client/_compat.py +18 -3
  3. {xinference_client-4.2.0 → xinference_client-4.3.0}/xinference_client/_version.py +3 -3
  4. {xinference_client-4.2.0 → xinference_client-4.3.0}/xinference_client/client/common.py +16 -0
  5. {xinference_client-4.2.0 → xinference_client-4.3.0}/xinference_client/client/restful/async_restful_client.py +27 -12
  6. {xinference_client-4.2.0 → xinference_client-4.3.0}/xinference_client/client/restful/restful_client.py +65 -46
  7. {xinference_client-4.2.0 → xinference_client-4.3.0/xinference_client.egg-info}/PKG-INFO +1 -1
  8. {xinference_client-4.2.0 → xinference_client-4.3.0}/LICENSE +0 -0
  9. {xinference_client-4.2.0 → xinference_client-4.3.0}/MANIFEST.in +0 -0
  10. {xinference_client-4.2.0 → xinference_client-4.3.0}/README.md +0 -0
  11. {xinference_client-4.2.0 → xinference_client-4.3.0}/pyproject.toml +0 -0
  12. {xinference_client-4.2.0 → xinference_client-4.3.0}/setup.cfg +0 -0
  13. {xinference_client-4.2.0 → xinference_client-4.3.0}/setup.py +0 -0
  14. {xinference_client-4.2.0 → xinference_client-4.3.0}/tests/test_async_client.py +0 -0
  15. {xinference_client-4.2.0 → xinference_client-4.3.0}/tests/test_async_client_cleanup.py +0 -0
  16. {xinference_client-4.2.0 → xinference_client-4.3.0}/third_party/inference/xinference/thirdparty/matcha/utils/monotonic_align/core.pyx +0 -0
  17. {xinference_client-4.2.0 → xinference_client-4.3.0}/versioneer.py +0 -0
  18. {xinference_client-4.2.0 → xinference_client-4.3.0}/xinference_client/__init__.py +0 -0
  19. {xinference_client-4.2.0 → xinference_client-4.3.0}/xinference_client/client/__init__.py +0 -0
  20. {xinference_client-4.2.0 → xinference_client-4.3.0}/xinference_client/client/restful/__init__.py +0 -0
  21. {xinference_client-4.2.0 → xinference_client-4.3.0}/xinference_client/fields.py +0 -0
  22. {xinference_client-4.2.0 → xinference_client-4.3.0}/xinference_client/types.py +0 -0
  23. {xinference_client-4.2.0 → xinference_client-4.3.0}/xinference_client.egg-info/SOURCES.txt +0 -0
  24. {xinference_client-4.2.0 → xinference_client-4.3.0}/xinference_client.egg-info/dependency_links.txt +0 -0
  25. {xinference_client-4.2.0 → xinference_client-4.3.0}/xinference_client.egg-info/not-zip-safe +0 -0
  26. {xinference_client-4.2.0 → xinference_client-4.3.0}/xinference_client.egg-info/requires.txt +0 -0
  27. {xinference_client-4.2.0 → xinference_client-4.3.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.2.0
3
+ Version: 4.3.0
4
4
  Summary: Client for Xinference
5
5
  Home-page: https://github.com/xorbitsai/inference-client
6
6
  Author: Qin Xuye
@@ -11,6 +11,7 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
+ import sys
14
15
  from typing import Dict, Iterable, List, Literal, Optional, Union
15
16
 
16
17
  from pydantic.version import VERSION as PYDANTIC_VERSION
@@ -23,6 +24,7 @@ if PYDANTIC_V2:
23
24
  BaseModel,
24
25
  Field,
25
26
  Protocol,
27
+ StrictInt,
26
28
  ValidationError,
27
29
  create_model,
28
30
  create_model_from_namedtuple,
@@ -40,6 +42,7 @@ else:
40
42
  BaseModel,
41
43
  Field,
42
44
  Protocol,
45
+ StrictInt,
43
46
  ValidationError,
44
47
  create_model,
45
48
  create_model_from_namedtuple,
@@ -65,11 +68,23 @@ from openai.types.shared_params.response_format_json_object import (
65
68
  )
66
69
  from openai.types.shared_params.response_format_text import ResponseFormatText
67
70
 
68
- OpenAIChatCompletionStreamOptionsParam = create_model_from_typeddict(
71
+
72
+ def _create_model_from_openai_typeddict(typeddict_cls):
73
+ model = create_model_from_typeddict(typeddict_cls)
74
+ # Python 3.14 defers annotation evaluation (PEP 649), so pydantic v1 leaves
75
+ # the TypedDict fields as unresolved ForwardRefs; resolve them in the
76
+ # namespace of the module that defines the TypedDict.
77
+ model.update_forward_refs(**vars(sys.modules[typeddict_cls.__module__]))
78
+ return model
79
+
80
+
81
+ OpenAIChatCompletionStreamOptionsParam = _create_model_from_openai_typeddict(
69
82
  ChatCompletionStreamOptionsParam
70
83
  )
71
- OpenAIChatCompletionToolParam = create_model_from_typeddict(ChatCompletionToolParam)
72
- OpenAIChatCompletionNamedToolChoiceParam = create_model_from_typeddict(
84
+ OpenAIChatCompletionToolParam = _create_model_from_openai_typeddict(
85
+ ChatCompletionToolParam
86
+ )
87
+ OpenAIChatCompletionNamedToolChoiceParam = _create_model_from_openai_typeddict(
73
88
  ChatCompletionNamedToolChoiceParam
74
89
  )
75
90
  from openai._types import Body
@@ -8,11 +8,11 @@ import json
8
8
 
9
9
  version_json = '''
10
10
  {
11
- "date": "2026-11-07T16:20:12+0800",
11
+ "date": "2026-11-26T16:25:20+0800",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "126f5b56ffbab1bda41d00c36731e26a91773281",
15
- "version": "4.2.0"
14
+ "full-revisionid": "0fd4fc33a816d81f822532363a2517c0f9b2141c",
15
+ "version": "4.3.0"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
@@ -30,6 +30,14 @@ def is_http_url(value: str) -> bool:
30
30
  return value.lower().startswith(("http://", "https://"))
31
31
 
32
32
 
33
+ def read_file_input(value: Union[str, bytes]) -> bytes:
34
+ """Return the bytes of an upload given as a local file path or as bytes."""
35
+ if isinstance(value, str):
36
+ with open(value, "rb") as f:
37
+ return f.read()
38
+ return value
39
+
40
+
33
41
  def encode_world_reference(reference: Union[str, bytes], media_type: str) -> str:
34
42
  if isinstance(reference, str) and not os.path.isfile(reference):
35
43
  return reference
@@ -78,7 +86,11 @@ def streaming_response_iterator(
78
86
 
79
87
  """
80
88
 
89
+ first_line = True
81
90
  for line in response_lines:
91
+ if first_line:
92
+ line = line.removeprefix(b"\xef\xbb\xbf")
93
+ first_line = False
82
94
  line = line.strip()
83
95
  if line.startswith(b"data:"):
84
96
  json_str = line[len(b"data:") :].strip()
@@ -127,7 +139,11 @@ async def async_streaming_response_iterator(
127
139
  if _prime:
128
140
  # Enter the cleanup scope before handing the stream to the caller.
129
141
  yield None
142
+ first_line = True
130
143
  async for line in response_lines:
144
+ if first_line:
145
+ line = line.removeprefix(b"\xef\xbb\xbf")
146
+ first_line = False
131
147
  line = line.strip()
132
148
  if line.startswith(b"data:"):
133
149
  json_str = line[len(b"data:") :].strip()
@@ -25,6 +25,7 @@ from ..common import (
25
25
  encode_world_reference,
26
26
  is_http_url,
27
27
  normalize_endpoint,
28
+ read_file_input,
28
29
  )
29
30
 
30
31
  if TYPE_CHECKING:
@@ -371,6 +372,10 @@ class AsyncRESTfulImageModelHandle(AsyncRESTfulModelHandle):
371
372
  :param image:
372
373
  """
373
374
  url = f"{self._base_url}/v1/images/variations"
375
+ if isinstance(image, list):
376
+ image = [await self._read_image(img) for img in image]
377
+ else:
378
+ image = await self._read_image(image)
374
379
  params = {
375
380
  "model": self._model_uid,
376
381
  "prompt": prompt,
@@ -445,9 +450,17 @@ class AsyncRESTfulImageModelHandle(AsyncRESTfulModelHandle):
445
450
  await _release_response(response)
446
451
  except (aiohttp.ClientError, asyncio.TimeoutError) as error:
447
452
  raise RuntimeError(
448
- f"Failed to download an image for editing, detail: {error}"
453
+ f"Failed to download an image, detail: {error}"
449
454
  ) from error
450
455
 
456
+ async def _read_image(self, image: Any) -> Any:
457
+ """Return the upload content of an image URL, local file path or bytes."""
458
+ image = await self._download_if_url(image)
459
+ if isinstance(image, str):
460
+ with open(image, "rb") as f:
461
+ return f.read()
462
+ return image
463
+
451
464
  async def image_edit(
452
465
  self,
453
466
  images: Union[Union[str, bytes], List[Union[str, bytes]]],
@@ -655,6 +668,8 @@ class AsyncRESTfulImageModelHandle(AsyncRESTfulModelHandle):
655
668
  :param image:
656
669
  """
657
670
  url = f"{self._base_url}/v1/images/inpainting"
671
+ image = await self._read_image(image)
672
+ mask_image = await self._read_image(mask_image)
658
673
  params = {
659
674
  "model": self._model_uid,
660
675
  "prompt": prompt,
@@ -689,6 +704,7 @@ class AsyncRESTfulImageModelHandle(AsyncRESTfulModelHandle):
689
704
 
690
705
  async def ocr(self, image: Union[str, bytes], **kwargs):
691
706
  url = f"{self._base_url}/v1/images/ocr"
707
+ image = await self._read_image(image)
692
708
  # aiohttp does not understand requests-style (key, (filename, value))
693
709
  # tuples; build a proper multipart form instead.
694
710
  form = aiohttp.FormData()
@@ -763,7 +779,7 @@ class AsyncRESTfulVideoModelHandle(AsyncRESTfulModelHandle):
763
779
  Parameters
764
780
  ----------
765
781
  image: `Union[str, bytes]`
766
- The input image to condition the generation on.
782
+ The input image to condition the generation on, as a local file path or bytes.
767
783
  prompt: `str` or `List[str]`
768
784
  The prompt or prompts to guide video generation. If not defined, you need to pass `prompt_embeds`.
769
785
  negative_prompt (`str` or `List[str]`, *optional*):
@@ -790,14 +806,13 @@ class AsyncRESTfulVideoModelHandle(AsyncRESTfulModelHandle):
790
806
  for key, value in params.items():
791
807
  data.add_field(key, str(value))
792
808
  data.add_field(
793
- "image", image, filename="image", content_type="application/octet-stream"
809
+ "image",
810
+ read_file_input(image),
811
+ filename="image",
812
+ content_type="application/octet-stream",
794
813
  )
795
814
  if video is not None:
796
- if isinstance(video, str):
797
- with open(video, "rb") as f:
798
- video_data = f.read()
799
- else:
800
- video_data = video
815
+ video_data = read_file_input(video)
801
816
  data.add_field(
802
817
  "video",
803
818
  video_data,
@@ -829,9 +844,9 @@ class AsyncRESTfulVideoModelHandle(AsyncRESTfulModelHandle):
829
844
  Parameters
830
845
  ----------
831
846
  first_frame: `Union[str, bytes]`
832
- The first frame to condition the generation on.
847
+ The first frame to condition the generation on, as a local file path or bytes.
833
848
  last_frame: `Union[str, bytes]`
834
- The last frame to condition the generation on.
849
+ The last frame to condition the generation on, as a local file path or bytes.
835
850
  prompt: `str` or `List[str]`
836
851
  The prompt or prompts to guide video generation. If not defined, you need to pass `prompt_embeds`.
837
852
  negative_prompt (`str` or `List[str]`, *optional*):
@@ -857,13 +872,13 @@ class AsyncRESTfulVideoModelHandle(AsyncRESTfulModelHandle):
857
872
  data.add_field(key, str(value))
858
873
  data.add_field(
859
874
  "first_frame",
860
- first_frame,
875
+ read_file_input(first_frame),
861
876
  filename="image",
862
877
  content_type="application/octet-stream",
863
878
  )
864
879
  data.add_field(
865
880
  "last_frame",
866
- last_frame,
881
+ read_file_input(last_frame),
867
882
  filename="image",
868
883
  content_type="application/octet-stream",
869
884
  )
@@ -23,6 +23,7 @@ from ..common import (
23
23
  encode_world_reference,
24
24
  is_http_url,
25
25
  normalize_endpoint,
26
+ read_file_input,
26
27
  streaming_response_iterator,
27
28
  )
28
29
 
@@ -326,6 +327,10 @@ class RESTfulImageModelHandle(RESTfulModelHandle):
326
327
  :param image:
327
328
  """
328
329
  url = f"{self._base_url}/v1/images/variations"
330
+ if isinstance(image, list):
331
+ image = [self._read_image(img) for img in image]
332
+ else:
333
+ image = self._read_image(image)
329
334
  params = {
330
335
  "model": self._model_uid,
331
336
  "prompt": prompt,
@@ -376,9 +381,17 @@ class RESTfulImageModelHandle(RESTfulModelHandle):
376
381
  return response.content
377
382
  except requests.RequestException as error:
378
383
  raise RuntimeError(
379
- f"Failed to download an image for editing, detail: {error}"
384
+ f"Failed to download an image, detail: {error}"
380
385
  ) from error
381
386
 
387
+ def _read_image(self, image: Any) -> Any:
388
+ """Return the upload content of an image URL, local file path or bytes."""
389
+ image = self._download_if_url(image)
390
+ if isinstance(image, str):
391
+ with open(image, "rb") as f:
392
+ return f.read()
393
+ return image
394
+
382
395
  def image_edit(
383
396
  self,
384
397
  images: Union[Union[str, bytes], List[Union[str, bytes]]],
@@ -458,44 +471,49 @@ class RESTfulImageModelHandle(RESTfulModelHandle):
458
471
  if value is not None:
459
472
  files.append((key, (None, value)))
460
473
 
461
- # Handle single image or multiple images using requests format
462
- if isinstance(images, list):
463
- # Validate image list is not empty
464
- if len(images) == 0:
465
- raise ValueError("Image list cannot be empty")
466
- # Multiple images - send as image[] array
467
- for i, img in enumerate(images):
468
- if isinstance(img, str):
474
+ try:
475
+ # Handle single image or multiple images using requests format
476
+ if isinstance(images, list):
477
+ # Validate image list is not empty
478
+ if len(images) == 0:
479
+ raise ValueError("Image list cannot be empty")
480
+ # Multiple images - send as image[] array
481
+ for i, img in enumerate(images):
482
+ if isinstance(img, str):
483
+ # File path - open file
484
+ f = open(img, "rb")
485
+ files.append(
486
+ (f"images[]", (f"image_{i}", f, "application/octet-stream"))
487
+ )
488
+ else:
489
+ # Binary data
490
+ files.append(
491
+ (
492
+ f"images[]",
493
+ (f"image_{i}", img, "application/octet-stream"),
494
+ )
495
+ )
496
+ else:
497
+ # Single image
498
+ if isinstance(images, str):
469
499
  # File path - open file
470
- f = open(img, "rb")
471
- files.append(
472
- (f"images[]", (f"image_{i}", f, "application/octet-stream"))
473
- )
500
+ f = open(images, "rb")
501
+ files.append(("images", ("image", f, "application/octet-stream")))
474
502
  else:
475
503
  # Binary data
476
504
  files.append(
477
- (f"images[]", (f"image_{i}", img, "application/octet-stream"))
505
+ ("images", ("image", images, "application/octet-stream"))
478
506
  )
479
- else:
480
- # Single image
481
- if isinstance(images, str):
482
- # File path - open file
483
- f = open(images, "rb")
484
- files.append(("images", ("image", f, "application/octet-stream")))
485
- else:
486
- # Binary data
487
- files.append(("images", ("image", images, "application/octet-stream")))
488
-
489
- if mask is not None:
490
- if isinstance(mask, str):
491
- # File path - open file
492
- f = open(mask, "rb")
493
- files.append(("mask", ("mask", f, "application/octet-stream")))
494
- else:
495
- # Binary data
496
- files.append(("mask", ("mask", mask, "application/octet-stream")))
497
507
 
498
- try:
508
+ if mask is not None:
509
+ if isinstance(mask, str):
510
+ # File path - open file
511
+ f = open(mask, "rb")
512
+ files.append(("mask", ("mask", f, "application/octet-stream")))
513
+ else:
514
+ # Binary data
515
+ files.append(("mask", ("mask", mask, "application/octet-stream")))
516
+
499
517
  response = self.session.post(url, files=files, headers=self.auth_headers)
500
518
  if response.status_code != 200:
501
519
  raise RuntimeError(
@@ -566,6 +584,8 @@ class RESTfulImageModelHandle(RESTfulModelHandle):
566
584
  :param image:
567
585
  """
568
586
  url = f"{self._base_url}/v1/images/inpainting"
587
+ image = self._read_image(image)
588
+ mask_image = self._read_image(mask_image)
569
589
  params = {
570
590
  "model": self._model_uid,
571
591
  "prompt": prompt,
@@ -593,6 +613,7 @@ class RESTfulImageModelHandle(RESTfulModelHandle):
593
613
 
594
614
  def ocr(self, image: Union[str, bytes], **kwargs):
595
615
  url = f"{self._base_url}/v1/images/ocr"
616
+ image = self._read_image(image)
596
617
  params = {
597
618
  "model": self._model_uid,
598
619
  "kwargs": json.dumps(kwargs),
@@ -663,7 +684,7 @@ class RESTfulVideoModelHandle(RESTfulModelHandle):
663
684
  Parameters
664
685
  ----------
665
686
  image: `Union[str, bytes]`
666
- The input image to condition the generation on.
687
+ The input image to condition the generation on, as a local file path or bytes.
667
688
  prompt: `str` or `List[str]`
668
689
  The prompt or prompts to guide video generation. If not defined, you need to pass `prompt_embeds`.
669
690
  negative_prompt (`str` or `List[str]`, *optional*):
@@ -688,13 +709,11 @@ class RESTfulVideoModelHandle(RESTfulModelHandle):
688
709
  files: List[Any] = []
689
710
  for key, value in params.items():
690
711
  files.append((key, (None, value)))
691
- files.append(("image", ("image", image, "application/octet-stream")))
712
+ files.append(
713
+ ("image", ("image", read_file_input(image), "application/octet-stream"))
714
+ )
692
715
  if video is not None:
693
- if isinstance(video, str):
694
- with open(video, "rb") as f:
695
- video_data = f.read()
696
- else:
697
- video_data = video
716
+ video_data = read_file_input(video)
698
717
  files.append(
699
718
  (
700
719
  "video",
@@ -725,9 +744,9 @@ class RESTfulVideoModelHandle(RESTfulModelHandle):
725
744
  Parameters
726
745
  ----------
727
746
  first_frame: `Union[str, bytes]`
728
- The first frame to condition the generation on.
747
+ The first frame to condition the generation on, as a local file path or bytes.
729
748
  last_frame: `Union[str, bytes]`
730
- The last frame to condition the generation on.
749
+ The last frame to condition the generation on, as a local file path or bytes.
731
750
  prompt: `str` or `List[str]`
732
751
  The prompt or prompts to guide video generation. If not defined, you need to pass `prompt_embeds`.
733
752
  negative_prompt (`str` or `List[str]`, *optional*):
@@ -750,10 +769,10 @@ class RESTfulVideoModelHandle(RESTfulModelHandle):
750
769
  files: List[Any] = []
751
770
  for key, value in params.items():
752
771
  files.append((key, (None, value)))
753
- files.append(
754
- ("first_frame", ("image", first_frame, "application/octet-stream"))
755
- )
756
- files.append(("last_frame", ("image", last_frame, "application/octet-stream")))
772
+ for key, frame in (("first_frame", first_frame), ("last_frame", last_frame)):
773
+ files.append(
774
+ (key, ("image", read_file_input(frame), "application/octet-stream"))
775
+ )
757
776
  response = self.session.post(url, files=files, headers=self.auth_headers)
758
777
  if response.status_code != 200:
759
778
  raise RuntimeError(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xinference-client
3
- Version: 4.2.0
3
+ Version: 4.3.0
4
4
  Summary: Client for Xinference
5
5
  Home-page: https://github.com/xorbitsai/inference-client
6
6
  Author: Qin Xuye