huggingface-hub 0.34.4__py3-none-any.whl → 1.0.0rc0__py3-none-any.whl
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.
Potentially problematic release.
This version of huggingface-hub might be problematic. Click here for more details.
- huggingface_hub/__init__.py +46 -45
- huggingface_hub/_commit_api.py +28 -28
- huggingface_hub/_commit_scheduler.py +11 -8
- huggingface_hub/_inference_endpoints.py +8 -8
- huggingface_hub/_jobs_api.py +167 -10
- huggingface_hub/_login.py +13 -39
- huggingface_hub/_oauth.py +8 -8
- huggingface_hub/_snapshot_download.py +14 -28
- huggingface_hub/_space_api.py +4 -4
- huggingface_hub/_tensorboard_logger.py +13 -14
- huggingface_hub/_upload_large_folder.py +15 -15
- huggingface_hub/_webhooks_payload.py +3 -3
- huggingface_hub/_webhooks_server.py +2 -2
- huggingface_hub/cli/_cli_utils.py +2 -2
- huggingface_hub/cli/auth.py +5 -6
- huggingface_hub/cli/cache.py +14 -20
- huggingface_hub/cli/download.py +4 -4
- huggingface_hub/cli/jobs.py +560 -11
- huggingface_hub/cli/lfs.py +4 -4
- huggingface_hub/cli/repo.py +7 -7
- huggingface_hub/cli/repo_files.py +2 -2
- huggingface_hub/cli/upload.py +4 -4
- huggingface_hub/cli/upload_large_folder.py +3 -3
- huggingface_hub/commands/_cli_utils.py +2 -2
- huggingface_hub/commands/delete_cache.py +13 -13
- huggingface_hub/commands/download.py +4 -13
- huggingface_hub/commands/lfs.py +4 -4
- huggingface_hub/commands/repo_files.py +2 -2
- huggingface_hub/commands/scan_cache.py +1 -1
- huggingface_hub/commands/tag.py +1 -3
- huggingface_hub/commands/upload.py +4 -4
- huggingface_hub/commands/upload_large_folder.py +3 -3
- huggingface_hub/commands/user.py +5 -6
- huggingface_hub/community.py +5 -5
- huggingface_hub/constants.py +3 -41
- huggingface_hub/dataclasses.py +16 -19
- huggingface_hub/errors.py +42 -29
- huggingface_hub/fastai_utils.py +8 -9
- huggingface_hub/file_download.py +153 -252
- huggingface_hub/hf_api.py +815 -600
- huggingface_hub/hf_file_system.py +98 -62
- huggingface_hub/hub_mixin.py +37 -57
- huggingface_hub/inference/_client.py +177 -325
- huggingface_hub/inference/_common.py +110 -124
- huggingface_hub/inference/_generated/_async_client.py +226 -432
- huggingface_hub/inference/_generated/types/automatic_speech_recognition.py +3 -3
- huggingface_hub/inference/_generated/types/base.py +10 -7
- huggingface_hub/inference/_generated/types/chat_completion.py +18 -16
- huggingface_hub/inference/_generated/types/depth_estimation.py +2 -2
- huggingface_hub/inference/_generated/types/document_question_answering.py +2 -2
- huggingface_hub/inference/_generated/types/feature_extraction.py +2 -2
- huggingface_hub/inference/_generated/types/fill_mask.py +2 -2
- huggingface_hub/inference/_generated/types/sentence_similarity.py +3 -3
- huggingface_hub/inference/_generated/types/summarization.py +2 -2
- huggingface_hub/inference/_generated/types/table_question_answering.py +4 -4
- huggingface_hub/inference/_generated/types/text2text_generation.py +2 -2
- huggingface_hub/inference/_generated/types/text_generation.py +10 -10
- huggingface_hub/inference/_generated/types/text_to_video.py +2 -2
- huggingface_hub/inference/_generated/types/token_classification.py +2 -2
- huggingface_hub/inference/_generated/types/translation.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_classification.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_image_classification.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_object_detection.py +1 -3
- huggingface_hub/inference/_mcp/_cli_hacks.py +3 -3
- huggingface_hub/inference/_mcp/agent.py +3 -3
- huggingface_hub/inference/_mcp/cli.py +1 -1
- huggingface_hub/inference/_mcp/constants.py +2 -3
- huggingface_hub/inference/_mcp/mcp_client.py +58 -30
- huggingface_hub/inference/_mcp/types.py +10 -7
- huggingface_hub/inference/_mcp/utils.py +11 -7
- huggingface_hub/inference/_providers/__init__.py +2 -2
- huggingface_hub/inference/_providers/_common.py +49 -25
- huggingface_hub/inference/_providers/black_forest_labs.py +6 -6
- huggingface_hub/inference/_providers/cohere.py +3 -3
- huggingface_hub/inference/_providers/fal_ai.py +25 -25
- huggingface_hub/inference/_providers/featherless_ai.py +4 -4
- huggingface_hub/inference/_providers/fireworks_ai.py +3 -3
- huggingface_hub/inference/_providers/hf_inference.py +28 -20
- huggingface_hub/inference/_providers/hyperbolic.py +4 -4
- huggingface_hub/inference/_providers/nebius.py +10 -10
- huggingface_hub/inference/_providers/novita.py +5 -5
- huggingface_hub/inference/_providers/nscale.py +4 -4
- huggingface_hub/inference/_providers/replicate.py +15 -15
- huggingface_hub/inference/_providers/sambanova.py +6 -6
- huggingface_hub/inference/_providers/together.py +7 -7
- huggingface_hub/lfs.py +20 -31
- huggingface_hub/repocard.py +18 -18
- huggingface_hub/repocard_data.py +56 -56
- huggingface_hub/serialization/__init__.py +0 -1
- huggingface_hub/serialization/_base.py +9 -9
- huggingface_hub/serialization/_dduf.py +7 -7
- huggingface_hub/serialization/_torch.py +28 -28
- huggingface_hub/utils/__init__.py +10 -4
- huggingface_hub/utils/_auth.py +5 -5
- huggingface_hub/utils/_cache_manager.py +31 -31
- huggingface_hub/utils/_deprecation.py +1 -1
- huggingface_hub/utils/_dotenv.py +3 -3
- huggingface_hub/utils/_fixes.py +0 -10
- huggingface_hub/utils/_git_credential.py +4 -4
- huggingface_hub/utils/_headers.py +7 -29
- huggingface_hub/utils/_http.py +366 -208
- huggingface_hub/utils/_pagination.py +4 -4
- huggingface_hub/utils/_paths.py +5 -5
- huggingface_hub/utils/_runtime.py +15 -13
- huggingface_hub/utils/_safetensors.py +21 -21
- huggingface_hub/utils/_subprocess.py +9 -9
- huggingface_hub/utils/_telemetry.py +3 -3
- huggingface_hub/utils/_typing.py +25 -5
- huggingface_hub/utils/_validators.py +53 -72
- huggingface_hub/utils/_xet.py +16 -16
- huggingface_hub/utils/_xet_progress_reporting.py +32 -11
- huggingface_hub/utils/insecure_hashlib.py +3 -9
- huggingface_hub/utils/tqdm.py +3 -3
- {huggingface_hub-0.34.4.dist-info → huggingface_hub-1.0.0rc0.dist-info}/METADATA +18 -29
- huggingface_hub-1.0.0rc0.dist-info/RECORD +161 -0
- huggingface_hub/inference_api.py +0 -217
- huggingface_hub/keras_mixin.py +0 -500
- huggingface_hub/repository.py +0 -1477
- huggingface_hub/serialization/_tensorflow.py +0 -95
- huggingface_hub/utils/_hf_folder.py +0 -68
- huggingface_hub-0.34.4.dist-info/RECORD +0 -166
- {huggingface_hub-0.34.4.dist-info → huggingface_hub-1.0.0rc0.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.34.4.dist-info → huggingface_hub-1.0.0rc0.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.34.4.dist-info → huggingface_hub-1.0.0rc0.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-0.34.4.dist-info → huggingface_hub-1.0.0rc0.dist-info}/top_level.txt +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import base64
|
|
2
2
|
import time
|
|
3
3
|
from abc import ABC
|
|
4
|
-
from typing import Any,
|
|
4
|
+
from typing import Any, Optional, Union
|
|
5
5
|
from urllib.parse import urlparse
|
|
6
6
|
|
|
7
7
|
from huggingface_hub import constants
|
|
@@ -22,7 +22,7 @@ class FalAITask(TaskProviderHelper, ABC):
|
|
|
22
22
|
def __init__(self, task: str):
|
|
23
23
|
super().__init__(provider="fal-ai", base_url="https://fal.run", task=task)
|
|
24
24
|
|
|
25
|
-
def _prepare_headers(self, headers:
|
|
25
|
+
def _prepare_headers(self, headers: dict, api_key: str) -> dict[str, Any]:
|
|
26
26
|
headers = super()._prepare_headers(headers, api_key)
|
|
27
27
|
if not api_key.startswith("hf_"):
|
|
28
28
|
headers["authorization"] = f"Key {api_key}"
|
|
@@ -36,7 +36,7 @@ class FalAIQueueTask(TaskProviderHelper, ABC):
|
|
|
36
36
|
def __init__(self, task: str):
|
|
37
37
|
super().__init__(provider="fal-ai", base_url="https://queue.fal.run", task=task)
|
|
38
38
|
|
|
39
|
-
def _prepare_headers(self, headers:
|
|
39
|
+
def _prepare_headers(self, headers: dict, api_key: str) -> dict[str, Any]:
|
|
40
40
|
headers = super()._prepare_headers(headers, api_key)
|
|
41
41
|
if not api_key.startswith("hf_"):
|
|
42
42
|
headers["authorization"] = f"Key {api_key}"
|
|
@@ -50,7 +50,7 @@ class FalAIQueueTask(TaskProviderHelper, ABC):
|
|
|
50
50
|
|
|
51
51
|
def get_response(
|
|
52
52
|
self,
|
|
53
|
-
response: Union[bytes,
|
|
53
|
+
response: Union[bytes, dict],
|
|
54
54
|
request_params: Optional[RequestParameters] = None,
|
|
55
55
|
) -> Any:
|
|
56
56
|
response_dict = _as_dict(response)
|
|
@@ -91,8 +91,8 @@ class FalAIAutomaticSpeechRecognitionTask(FalAITask):
|
|
|
91
91
|
super().__init__("automatic-speech-recognition")
|
|
92
92
|
|
|
93
93
|
def _prepare_payload_as_dict(
|
|
94
|
-
self, inputs: Any, parameters:
|
|
95
|
-
) -> Optional[
|
|
94
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
95
|
+
) -> Optional[dict]:
|
|
96
96
|
if isinstance(inputs, str) and inputs.startswith(("http://", "https://")):
|
|
97
97
|
# If input is a URL, pass it directly
|
|
98
98
|
audio_url = inputs
|
|
@@ -108,7 +108,7 @@ class FalAIAutomaticSpeechRecognitionTask(FalAITask):
|
|
|
108
108
|
|
|
109
109
|
return {"audio_url": audio_url, **filter_none(parameters)}
|
|
110
110
|
|
|
111
|
-
def get_response(self, response: Union[bytes,
|
|
111
|
+
def get_response(self, response: Union[bytes, dict], request_params: Optional[RequestParameters] = None) -> Any:
|
|
112
112
|
text = _as_dict(response)["text"]
|
|
113
113
|
if not isinstance(text, str):
|
|
114
114
|
raise ValueError(f"Unexpected output format from FalAI API. Expected string, got {type(text)}.")
|
|
@@ -120,9 +120,9 @@ class FalAITextToImageTask(FalAITask):
|
|
|
120
120
|
super().__init__("text-to-image")
|
|
121
121
|
|
|
122
122
|
def _prepare_payload_as_dict(
|
|
123
|
-
self, inputs: Any, parameters:
|
|
124
|
-
) -> Optional[
|
|
125
|
-
payload:
|
|
123
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
124
|
+
) -> Optional[dict]:
|
|
125
|
+
payload: dict[str, Any] = {
|
|
126
126
|
"prompt": inputs,
|
|
127
127
|
**filter_none(parameters),
|
|
128
128
|
}
|
|
@@ -145,7 +145,7 @@ class FalAITextToImageTask(FalAITask):
|
|
|
145
145
|
|
|
146
146
|
return payload
|
|
147
147
|
|
|
148
|
-
def get_response(self, response: Union[bytes,
|
|
148
|
+
def get_response(self, response: Union[bytes, dict], request_params: Optional[RequestParameters] = None) -> Any:
|
|
149
149
|
url = _as_dict(response)["images"][0]["url"]
|
|
150
150
|
return get_session().get(url).content
|
|
151
151
|
|
|
@@ -155,11 +155,11 @@ class FalAITextToSpeechTask(FalAITask):
|
|
|
155
155
|
super().__init__("text-to-speech")
|
|
156
156
|
|
|
157
157
|
def _prepare_payload_as_dict(
|
|
158
|
-
self, inputs: Any, parameters:
|
|
159
|
-
) -> Optional[
|
|
158
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
159
|
+
) -> Optional[dict]:
|
|
160
160
|
return {"text": inputs, **filter_none(parameters)}
|
|
161
161
|
|
|
162
|
-
def get_response(self, response: Union[bytes,
|
|
162
|
+
def get_response(self, response: Union[bytes, dict], request_params: Optional[RequestParameters] = None) -> Any:
|
|
163
163
|
url = _as_dict(response)["audio"]["url"]
|
|
164
164
|
return get_session().get(url).content
|
|
165
165
|
|
|
@@ -169,13 +169,13 @@ class FalAITextToVideoTask(FalAIQueueTask):
|
|
|
169
169
|
super().__init__("text-to-video")
|
|
170
170
|
|
|
171
171
|
def _prepare_payload_as_dict(
|
|
172
|
-
self, inputs: Any, parameters:
|
|
173
|
-
) -> Optional[
|
|
172
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
173
|
+
) -> Optional[dict]:
|
|
174
174
|
return {"prompt": inputs, **filter_none(parameters)}
|
|
175
175
|
|
|
176
176
|
def get_response(
|
|
177
177
|
self,
|
|
178
|
-
response: Union[bytes,
|
|
178
|
+
response: Union[bytes, dict],
|
|
179
179
|
request_params: Optional[RequestParameters] = None,
|
|
180
180
|
) -> Any:
|
|
181
181
|
output = super().get_response(response, request_params)
|
|
@@ -188,10 +188,10 @@ class FalAIImageToImageTask(FalAIQueueTask):
|
|
|
188
188
|
super().__init__("image-to-image")
|
|
189
189
|
|
|
190
190
|
def _prepare_payload_as_dict(
|
|
191
|
-
self, inputs: Any, parameters:
|
|
192
|
-
) -> Optional[
|
|
191
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
192
|
+
) -> Optional[dict]:
|
|
193
193
|
image_url = _as_url(inputs, default_mime_type="image/jpeg")
|
|
194
|
-
payload:
|
|
194
|
+
payload: dict[str, Any] = {
|
|
195
195
|
"image_url": image_url,
|
|
196
196
|
**filter_none(parameters),
|
|
197
197
|
}
|
|
@@ -207,7 +207,7 @@ class FalAIImageToImageTask(FalAIQueueTask):
|
|
|
207
207
|
|
|
208
208
|
def get_response(
|
|
209
209
|
self,
|
|
210
|
-
response: Union[bytes,
|
|
210
|
+
response: Union[bytes, dict],
|
|
211
211
|
request_params: Optional[RequestParameters] = None,
|
|
212
212
|
) -> Any:
|
|
213
213
|
output = super().get_response(response, request_params)
|
|
@@ -220,10 +220,10 @@ class FalAIImageToVideoTask(FalAIQueueTask):
|
|
|
220
220
|
super().__init__("image-to-video")
|
|
221
221
|
|
|
222
222
|
def _prepare_payload_as_dict(
|
|
223
|
-
self, inputs: Any, parameters:
|
|
224
|
-
) -> Optional[
|
|
223
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
224
|
+
) -> Optional[dict]:
|
|
225
225
|
image_url = _as_url(inputs, default_mime_type="image/jpeg")
|
|
226
|
-
payload:
|
|
226
|
+
payload: dict[str, Any] = {
|
|
227
227
|
"image_url": image_url,
|
|
228
228
|
**filter_none(parameters),
|
|
229
229
|
}
|
|
@@ -238,7 +238,7 @@ class FalAIImageToVideoTask(FalAIQueueTask):
|
|
|
238
238
|
|
|
239
239
|
def get_response(
|
|
240
240
|
self,
|
|
241
|
-
response: Union[bytes,
|
|
241
|
+
response: Union[bytes, dict],
|
|
242
242
|
request_params: Optional[RequestParameters] = None,
|
|
243
243
|
) -> Any:
|
|
244
244
|
output = super().get_response(response, request_params)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any,
|
|
1
|
+
from typing import Any, Optional, Union
|
|
2
2
|
|
|
3
3
|
from huggingface_hub.hf_api import InferenceProviderMapping
|
|
4
4
|
from huggingface_hub.inference._common import RequestParameters, _as_dict
|
|
@@ -15,14 +15,14 @@ class FeatherlessTextGenerationTask(BaseTextGenerationTask):
|
|
|
15
15
|
super().__init__(provider=_PROVIDER, base_url=_BASE_URL)
|
|
16
16
|
|
|
17
17
|
def _prepare_payload_as_dict(
|
|
18
|
-
self, inputs: Any, parameters:
|
|
19
|
-
) -> Optional[
|
|
18
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
19
|
+
) -> Optional[dict]:
|
|
20
20
|
params = filter_none(parameters.copy())
|
|
21
21
|
params["max_tokens"] = params.pop("max_new_tokens", None)
|
|
22
22
|
|
|
23
23
|
return {"prompt": inputs, **params, "model": provider_mapping_info.provider_id}
|
|
24
24
|
|
|
25
|
-
def get_response(self, response: Union[bytes,
|
|
25
|
+
def get_response(self, response: Union[bytes, dict], request_params: Optional[RequestParameters] = None) -> Any:
|
|
26
26
|
output = _as_dict(response)["choices"][0]
|
|
27
27
|
return {
|
|
28
28
|
"generated_text": output["text"],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any,
|
|
1
|
+
from typing import Any, Optional
|
|
2
2
|
|
|
3
3
|
from huggingface_hub.hf_api import InferenceProviderMapping
|
|
4
4
|
|
|
@@ -13,8 +13,8 @@ class FireworksAIConversationalTask(BaseConversationalTask):
|
|
|
13
13
|
return "/inference/v1/chat/completions"
|
|
14
14
|
|
|
15
15
|
def _prepare_payload_as_dict(
|
|
16
|
-
self, inputs: Any, parameters:
|
|
17
|
-
) -> Optional[
|
|
16
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
17
|
+
) -> Optional[dict]:
|
|
18
18
|
payload = super()._prepare_payload_as_dict(inputs, parameters, provider_mapping_info)
|
|
19
19
|
response_format = parameters.get("response_format")
|
|
20
20
|
if isinstance(response_format, dict) and response_format.get("type") == "json_schema":
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import json
|
|
2
2
|
from functools import lru_cache
|
|
3
3
|
from pathlib import Path
|
|
4
|
-
from typing import Any,
|
|
4
|
+
from typing import Any, Optional, Union
|
|
5
5
|
from urllib.parse import urlparse, urlunparse
|
|
6
6
|
|
|
7
7
|
from huggingface_hub import constants
|
|
8
8
|
from huggingface_hub.hf_api import InferenceProviderMapping
|
|
9
|
-
from huggingface_hub.inference._common import
|
|
9
|
+
from huggingface_hub.inference._common import (
|
|
10
|
+
MimeBytes,
|
|
11
|
+
RequestParameters,
|
|
12
|
+
_b64_encode,
|
|
13
|
+
_bytes_to_dict,
|
|
14
|
+
_open_as_mime_bytes,
|
|
15
|
+
)
|
|
10
16
|
from huggingface_hub.inference._providers._common import TaskProviderHelper, filter_none
|
|
11
17
|
from huggingface_hub.utils import build_hf_headers, get_session, get_token, hf_raise_for_status
|
|
12
18
|
|
|
@@ -54,8 +60,8 @@ class HFInferenceTask(TaskProviderHelper):
|
|
|
54
60
|
)
|
|
55
61
|
|
|
56
62
|
def _prepare_payload_as_dict(
|
|
57
|
-
self, inputs: Any, parameters:
|
|
58
|
-
) -> Optional[
|
|
63
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
64
|
+
) -> Optional[dict]:
|
|
59
65
|
if isinstance(inputs, bytes):
|
|
60
66
|
raise ValueError(f"Unexpected binary input for task {self.task}.")
|
|
61
67
|
if isinstance(inputs, Path):
|
|
@@ -65,17 +71,17 @@ class HFInferenceTask(TaskProviderHelper):
|
|
|
65
71
|
|
|
66
72
|
class HFInferenceBinaryInputTask(HFInferenceTask):
|
|
67
73
|
def _prepare_payload_as_dict(
|
|
68
|
-
self, inputs: Any, parameters:
|
|
69
|
-
) -> Optional[
|
|
74
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
75
|
+
) -> Optional[dict]:
|
|
70
76
|
return None
|
|
71
77
|
|
|
72
78
|
def _prepare_payload_as_bytes(
|
|
73
79
|
self,
|
|
74
80
|
inputs: Any,
|
|
75
|
-
parameters:
|
|
81
|
+
parameters: dict,
|
|
76
82
|
provider_mapping_info: InferenceProviderMapping,
|
|
77
|
-
extra_payload: Optional[
|
|
78
|
-
) -> Optional[
|
|
83
|
+
extra_payload: Optional[dict],
|
|
84
|
+
) -> Optional[MimeBytes]:
|
|
79
85
|
parameters = filter_none(parameters)
|
|
80
86
|
extra_payload = extra_payload or {}
|
|
81
87
|
has_parameters = len(parameters) > 0 or len(extra_payload) > 0
|
|
@@ -86,12 +92,13 @@ class HFInferenceBinaryInputTask(HFInferenceTask):
|
|
|
86
92
|
|
|
87
93
|
# Send inputs as raw content when no parameters are provided
|
|
88
94
|
if not has_parameters:
|
|
89
|
-
|
|
90
|
-
data_as_bytes = data if isinstance(data, bytes) else data.read()
|
|
91
|
-
return data_as_bytes
|
|
95
|
+
return _open_as_mime_bytes(inputs)
|
|
92
96
|
|
|
93
97
|
# Otherwise encode as b64
|
|
94
|
-
return
|
|
98
|
+
return MimeBytes(
|
|
99
|
+
json.dumps({"inputs": _b64_encode(inputs), "parameters": parameters, **extra_payload}).encode("utf-8"),
|
|
100
|
+
mime_type="application/json",
|
|
101
|
+
)
|
|
95
102
|
|
|
96
103
|
|
|
97
104
|
class HFInferenceConversational(HFInferenceTask):
|
|
@@ -99,8 +106,8 @@ class HFInferenceConversational(HFInferenceTask):
|
|
|
99
106
|
super().__init__("conversational")
|
|
100
107
|
|
|
101
108
|
def _prepare_payload_as_dict(
|
|
102
|
-
self, inputs: Any, parameters:
|
|
103
|
-
) -> Optional[
|
|
109
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
110
|
+
) -> Optional[dict]:
|
|
104
111
|
payload = filter_none(parameters)
|
|
105
112
|
mapped_model = provider_mapping_info.provider_id
|
|
106
113
|
payload_model = parameters.get("model") or mapped_model
|
|
@@ -144,11 +151,12 @@ def _build_chat_completion_url(model_url: str) -> str:
|
|
|
144
151
|
new_path = path + "/v1/chat/completions"
|
|
145
152
|
|
|
146
153
|
# Reconstruct the URL with the new path and original query parameters.
|
|
147
|
-
|
|
154
|
+
new_parsed = parsed._replace(path=new_path)
|
|
155
|
+
return str(urlunparse(new_parsed))
|
|
148
156
|
|
|
149
157
|
|
|
150
158
|
@lru_cache(maxsize=1)
|
|
151
|
-
def _fetch_recommended_models() ->
|
|
159
|
+
def _fetch_recommended_models() -> dict[str, Optional[str]]:
|
|
152
160
|
response = get_session().get(f"{constants.ENDPOINT}/api/tasks", headers=build_hf_headers())
|
|
153
161
|
hf_raise_for_status(response)
|
|
154
162
|
return {task: next(iter(details["widgetModels"]), None) for task, details in response.json().items()}
|
|
@@ -203,8 +211,8 @@ class HFInferenceFeatureExtractionTask(HFInferenceTask):
|
|
|
203
211
|
super().__init__("feature-extraction")
|
|
204
212
|
|
|
205
213
|
def _prepare_payload_as_dict(
|
|
206
|
-
self, inputs: Any, parameters:
|
|
207
|
-
) -> Optional[
|
|
214
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
215
|
+
) -> Optional[dict]:
|
|
208
216
|
if isinstance(inputs, bytes):
|
|
209
217
|
raise ValueError(f"Unexpected binary input for task {self.task}.")
|
|
210
218
|
if isinstance(inputs, Path):
|
|
@@ -214,7 +222,7 @@ class HFInferenceFeatureExtractionTask(HFInferenceTask):
|
|
|
214
222
|
# See specs: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/src/tasks/feature-extraction/spec/input.json
|
|
215
223
|
return {"inputs": inputs, **filter_none(parameters)}
|
|
216
224
|
|
|
217
|
-
def get_response(self, response: Union[bytes,
|
|
225
|
+
def get_response(self, response: Union[bytes, dict], request_params: Optional[RequestParameters] = None) -> Any:
|
|
218
226
|
if isinstance(response, bytes):
|
|
219
227
|
return _bytes_to_dict(response)
|
|
220
228
|
return response
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import base64
|
|
2
|
-
from typing import Any,
|
|
2
|
+
from typing import Any, Optional, Union
|
|
3
3
|
|
|
4
4
|
from huggingface_hub.hf_api import InferenceProviderMapping
|
|
5
5
|
from huggingface_hub.inference._common import RequestParameters, _as_dict
|
|
@@ -14,8 +14,8 @@ class HyperbolicTextToImageTask(TaskProviderHelper):
|
|
|
14
14
|
return "/v1/images/generations"
|
|
15
15
|
|
|
16
16
|
def _prepare_payload_as_dict(
|
|
17
|
-
self, inputs: Any, parameters:
|
|
18
|
-
) -> Optional[
|
|
17
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
18
|
+
) -> Optional[dict]:
|
|
19
19
|
mapped_model = provider_mapping_info.provider_id
|
|
20
20
|
parameters = filter_none(parameters)
|
|
21
21
|
if "num_inference_steps" in parameters:
|
|
@@ -29,7 +29,7 @@ class HyperbolicTextToImageTask(TaskProviderHelper):
|
|
|
29
29
|
parameters["height"] = 512
|
|
30
30
|
return {"prompt": inputs, "model_name": mapped_model, **parameters}
|
|
31
31
|
|
|
32
|
-
def get_response(self, response: Union[bytes,
|
|
32
|
+
def get_response(self, response: Union[bytes, dict], request_params: Optional[RequestParameters] = None) -> Any:
|
|
33
33
|
response_dict = _as_dict(response)
|
|
34
34
|
return base64.b64decode(response_dict["images"][0]["image"])
|
|
35
35
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import base64
|
|
2
|
-
from typing import Any,
|
|
2
|
+
from typing import Any, Optional, Union
|
|
3
3
|
|
|
4
4
|
from huggingface_hub.hf_api import InferenceProviderMapping
|
|
5
5
|
from huggingface_hub.inference._common import RequestParameters, _as_dict
|
|
@@ -15,7 +15,7 @@ class NebiusTextGenerationTask(BaseTextGenerationTask):
|
|
|
15
15
|
def __init__(self):
|
|
16
16
|
super().__init__(provider="nebius", base_url="https://api.studio.nebius.ai")
|
|
17
17
|
|
|
18
|
-
def get_response(self, response: Union[bytes,
|
|
18
|
+
def get_response(self, response: Union[bytes, dict], request_params: Optional[RequestParameters] = None) -> Any:
|
|
19
19
|
output = _as_dict(response)["choices"][0]
|
|
20
20
|
return {
|
|
21
21
|
"generated_text": output["text"],
|
|
@@ -31,8 +31,8 @@ class NebiusConversationalTask(BaseConversationalTask):
|
|
|
31
31
|
super().__init__(provider="nebius", base_url="https://api.studio.nebius.ai")
|
|
32
32
|
|
|
33
33
|
def _prepare_payload_as_dict(
|
|
34
|
-
self, inputs: Any, parameters:
|
|
35
|
-
) -> Optional[
|
|
34
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
35
|
+
) -> Optional[dict]:
|
|
36
36
|
payload = super()._prepare_payload_as_dict(inputs, parameters, provider_mapping_info)
|
|
37
37
|
response_format = parameters.get("response_format")
|
|
38
38
|
if isinstance(response_format, dict) and response_format.get("type") == "json_schema":
|
|
@@ -50,8 +50,8 @@ class NebiusTextToImageTask(TaskProviderHelper):
|
|
|
50
50
|
return "/v1/images/generations"
|
|
51
51
|
|
|
52
52
|
def _prepare_payload_as_dict(
|
|
53
|
-
self, inputs: Any, parameters:
|
|
54
|
-
) -> Optional[
|
|
53
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
54
|
+
) -> Optional[dict]:
|
|
55
55
|
mapped_model = provider_mapping_info.provider_id
|
|
56
56
|
parameters = filter_none(parameters)
|
|
57
57
|
if "guidance_scale" in parameters:
|
|
@@ -61,7 +61,7 @@ class NebiusTextToImageTask(TaskProviderHelper):
|
|
|
61
61
|
|
|
62
62
|
return {"prompt": inputs, **parameters, "model": mapped_model}
|
|
63
63
|
|
|
64
|
-
def get_response(self, response: Union[bytes,
|
|
64
|
+
def get_response(self, response: Union[bytes, dict], request_params: Optional[RequestParameters] = None) -> Any:
|
|
65
65
|
response_dict = _as_dict(response)
|
|
66
66
|
return base64.b64decode(response_dict["data"][0]["b64_json"])
|
|
67
67
|
|
|
@@ -74,10 +74,10 @@ class NebiusFeatureExtractionTask(TaskProviderHelper):
|
|
|
74
74
|
return "/v1/embeddings"
|
|
75
75
|
|
|
76
76
|
def _prepare_payload_as_dict(
|
|
77
|
-
self, inputs: Any, parameters:
|
|
78
|
-
) -> Optional[
|
|
77
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
78
|
+
) -> Optional[dict]:
|
|
79
79
|
return {"input": inputs, "model": provider_mapping_info.provider_id}
|
|
80
80
|
|
|
81
|
-
def get_response(self, response: Union[bytes,
|
|
81
|
+
def get_response(self, response: Union[bytes, dict], request_params: Optional[RequestParameters] = None) -> Any:
|
|
82
82
|
embeddings = _as_dict(response)["data"]
|
|
83
83
|
return [embedding["embedding"] for embedding in embeddings]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any,
|
|
1
|
+
from typing import Any, Optional, Union
|
|
2
2
|
|
|
3
3
|
from huggingface_hub.hf_api import InferenceProviderMapping
|
|
4
4
|
from huggingface_hub.inference._common import RequestParameters, _as_dict
|
|
@@ -23,7 +23,7 @@ class NovitaTextGenerationTask(BaseTextGenerationTask):
|
|
|
23
23
|
# there is no v1/ route for novita
|
|
24
24
|
return "/v3/openai/completions"
|
|
25
25
|
|
|
26
|
-
def get_response(self, response: Union[bytes,
|
|
26
|
+
def get_response(self, response: Union[bytes, dict], request_params: Optional[RequestParameters] = None) -> Any:
|
|
27
27
|
output = _as_dict(response)["choices"][0]
|
|
28
28
|
return {
|
|
29
29
|
"generated_text": output["text"],
|
|
@@ -51,11 +51,11 @@ class NovitaTextToVideoTask(TaskProviderHelper):
|
|
|
51
51
|
return f"/v3/hf/{mapped_model}"
|
|
52
52
|
|
|
53
53
|
def _prepare_payload_as_dict(
|
|
54
|
-
self, inputs: Any, parameters:
|
|
55
|
-
) -> Optional[
|
|
54
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
55
|
+
) -> Optional[dict]:
|
|
56
56
|
return {"prompt": inputs, **filter_none(parameters)}
|
|
57
57
|
|
|
58
|
-
def get_response(self, response: Union[bytes,
|
|
58
|
+
def get_response(self, response: Union[bytes, dict], request_params: Optional[RequestParameters] = None) -> Any:
|
|
59
59
|
response_dict = _as_dict(response)
|
|
60
60
|
if not (
|
|
61
61
|
isinstance(response_dict, dict)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import base64
|
|
2
|
-
from typing import Any,
|
|
2
|
+
from typing import Any, Optional, Union
|
|
3
3
|
|
|
4
4
|
from huggingface_hub.hf_api import InferenceProviderMapping
|
|
5
5
|
from huggingface_hub.inference._common import RequestParameters, _as_dict
|
|
@@ -20,8 +20,8 @@ class NscaleTextToImageTask(TaskProviderHelper):
|
|
|
20
20
|
return "/v1/images/generations"
|
|
21
21
|
|
|
22
22
|
def _prepare_payload_as_dict(
|
|
23
|
-
self, inputs: Any, parameters:
|
|
24
|
-
) -> Optional[
|
|
23
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
24
|
+
) -> Optional[dict]:
|
|
25
25
|
mapped_model = provider_mapping_info.provider_id
|
|
26
26
|
# Combine all parameters except inputs and parameters
|
|
27
27
|
parameters = filter_none(parameters)
|
|
@@ -39,6 +39,6 @@ class NscaleTextToImageTask(TaskProviderHelper):
|
|
|
39
39
|
}
|
|
40
40
|
return payload
|
|
41
41
|
|
|
42
|
-
def get_response(self, response: Union[bytes,
|
|
42
|
+
def get_response(self, response: Union[bytes, dict], request_params: Optional[RequestParameters] = None) -> Any:
|
|
43
43
|
response_dict = _as_dict(response)
|
|
44
44
|
return base64.b64decode(response_dict["data"][0]["b64_json"])
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any,
|
|
1
|
+
from typing import Any, Optional, Union
|
|
2
2
|
|
|
3
3
|
from huggingface_hub.hf_api import InferenceProviderMapping
|
|
4
4
|
from huggingface_hub.inference._common import RequestParameters, _as_dict, _as_url
|
|
@@ -14,7 +14,7 @@ class ReplicateTask(TaskProviderHelper):
|
|
|
14
14
|
def __init__(self, task: str):
|
|
15
15
|
super().__init__(provider=_PROVIDER, base_url=_BASE_URL, task=task)
|
|
16
16
|
|
|
17
|
-
def _prepare_headers(self, headers:
|
|
17
|
+
def _prepare_headers(self, headers: dict, api_key: str) -> dict[str, Any]:
|
|
18
18
|
headers = super()._prepare_headers(headers, api_key)
|
|
19
19
|
headers["Prefer"] = "wait"
|
|
20
20
|
return headers
|
|
@@ -25,16 +25,16 @@ class ReplicateTask(TaskProviderHelper):
|
|
|
25
25
|
return f"/v1/models/{mapped_model}/predictions"
|
|
26
26
|
|
|
27
27
|
def _prepare_payload_as_dict(
|
|
28
|
-
self, inputs: Any, parameters:
|
|
29
|
-
) -> Optional[
|
|
28
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
29
|
+
) -> Optional[dict]:
|
|
30
30
|
mapped_model = provider_mapping_info.provider_id
|
|
31
|
-
payload:
|
|
31
|
+
payload: dict[str, Any] = {"input": {"prompt": inputs, **filter_none(parameters)}}
|
|
32
32
|
if ":" in mapped_model:
|
|
33
33
|
version = mapped_model.split(":", 1)[1]
|
|
34
34
|
payload["version"] = version
|
|
35
35
|
return payload
|
|
36
36
|
|
|
37
|
-
def get_response(self, response: Union[bytes,
|
|
37
|
+
def get_response(self, response: Union[bytes, dict], request_params: Optional[RequestParameters] = None) -> Any:
|
|
38
38
|
response_dict = _as_dict(response)
|
|
39
39
|
if response_dict.get("output") is None:
|
|
40
40
|
raise TimeoutError(
|
|
@@ -52,9 +52,9 @@ class ReplicateTextToImageTask(ReplicateTask):
|
|
|
52
52
|
super().__init__("text-to-image")
|
|
53
53
|
|
|
54
54
|
def _prepare_payload_as_dict(
|
|
55
|
-
self, inputs: Any, parameters:
|
|
56
|
-
) -> Optional[
|
|
57
|
-
payload:
|
|
55
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
56
|
+
) -> Optional[dict]:
|
|
57
|
+
payload: dict = super()._prepare_payload_as_dict(inputs, parameters, provider_mapping_info) # type: ignore[assignment]
|
|
58
58
|
if provider_mapping_info.adapter_weights_path is not None:
|
|
59
59
|
payload["input"]["lora_weights"] = f"https://huggingface.co/{provider_mapping_info.hf_model_id}"
|
|
60
60
|
return payload
|
|
@@ -65,9 +65,9 @@ class ReplicateTextToSpeechTask(ReplicateTask):
|
|
|
65
65
|
super().__init__("text-to-speech")
|
|
66
66
|
|
|
67
67
|
def _prepare_payload_as_dict(
|
|
68
|
-
self, inputs: Any, parameters:
|
|
69
|
-
) -> Optional[
|
|
70
|
-
payload:
|
|
68
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
69
|
+
) -> Optional[dict]:
|
|
70
|
+
payload: dict = super()._prepare_payload_as_dict(inputs, parameters, provider_mapping_info) # type: ignore[assignment]
|
|
71
71
|
payload["input"]["text"] = payload["input"].pop("prompt") # rename "prompt" to "text" for TTS
|
|
72
72
|
return payload
|
|
73
73
|
|
|
@@ -77,11 +77,11 @@ class ReplicateImageToImageTask(ReplicateTask):
|
|
|
77
77
|
super().__init__("image-to-image")
|
|
78
78
|
|
|
79
79
|
def _prepare_payload_as_dict(
|
|
80
|
-
self, inputs: Any, parameters:
|
|
81
|
-
) -> Optional[
|
|
80
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
81
|
+
) -> Optional[dict]:
|
|
82
82
|
image_url = _as_url(inputs, default_mime_type="image/jpeg")
|
|
83
83
|
|
|
84
|
-
payload:
|
|
84
|
+
payload: dict[str, Any] = {"input": {"input_image": image_url, **filter_none(parameters)}}
|
|
85
85
|
|
|
86
86
|
mapped_model = provider_mapping_info.provider_id
|
|
87
87
|
if ":" in mapped_model:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any,
|
|
1
|
+
from typing import Any, Optional, Union
|
|
2
2
|
|
|
3
3
|
from huggingface_hub.hf_api import InferenceProviderMapping
|
|
4
4
|
from huggingface_hub.inference._common import RequestParameters, _as_dict
|
|
@@ -10,8 +10,8 @@ class SambanovaConversationalTask(BaseConversationalTask):
|
|
|
10
10
|
super().__init__(provider="sambanova", base_url="https://api.sambanova.ai")
|
|
11
11
|
|
|
12
12
|
def _prepare_payload_as_dict(
|
|
13
|
-
self, inputs: Any, parameters:
|
|
14
|
-
) -> Optional[
|
|
13
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
14
|
+
) -> Optional[dict]:
|
|
15
15
|
response_format_config = parameters.get("response_format")
|
|
16
16
|
if isinstance(response_format_config, dict):
|
|
17
17
|
if response_format_config.get("type") == "json_schema":
|
|
@@ -32,11 +32,11 @@ class SambanovaFeatureExtractionTask(TaskProviderHelper):
|
|
|
32
32
|
return "/v1/embeddings"
|
|
33
33
|
|
|
34
34
|
def _prepare_payload_as_dict(
|
|
35
|
-
self, inputs: Any, parameters:
|
|
36
|
-
) -> Optional[
|
|
35
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
36
|
+
) -> Optional[dict]:
|
|
37
37
|
parameters = filter_none(parameters)
|
|
38
38
|
return {"input": inputs, "model": provider_mapping_info.provider_id, **parameters}
|
|
39
39
|
|
|
40
|
-
def get_response(self, response: Union[bytes,
|
|
40
|
+
def get_response(self, response: Union[bytes, dict], request_params: Optional[RequestParameters] = None) -> Any:
|
|
41
41
|
embeddings = _as_dict(response)["data"]
|
|
42
42
|
return [embedding["embedding"] for embedding in embeddings]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import base64
|
|
2
2
|
from abc import ABC
|
|
3
|
-
from typing import Any,
|
|
3
|
+
from typing import Any, Optional, Union
|
|
4
4
|
|
|
5
5
|
from huggingface_hub.hf_api import InferenceProviderMapping
|
|
6
6
|
from huggingface_hub.inference._common import RequestParameters, _as_dict
|
|
@@ -36,7 +36,7 @@ class TogetherTextGenerationTask(BaseTextGenerationTask):
|
|
|
36
36
|
def __init__(self):
|
|
37
37
|
super().__init__(provider=_PROVIDER, base_url=_BASE_URL)
|
|
38
38
|
|
|
39
|
-
def get_response(self, response: Union[bytes,
|
|
39
|
+
def get_response(self, response: Union[bytes, dict], request_params: Optional[RequestParameters] = None) -> Any:
|
|
40
40
|
output = _as_dict(response)["choices"][0]
|
|
41
41
|
return {
|
|
42
42
|
"generated_text": output["text"],
|
|
@@ -52,8 +52,8 @@ class TogetherConversationalTask(BaseConversationalTask):
|
|
|
52
52
|
super().__init__(provider=_PROVIDER, base_url=_BASE_URL)
|
|
53
53
|
|
|
54
54
|
def _prepare_payload_as_dict(
|
|
55
|
-
self, inputs: Any, parameters:
|
|
56
|
-
) -> Optional[
|
|
55
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
56
|
+
) -> Optional[dict]:
|
|
57
57
|
payload = super()._prepare_payload_as_dict(inputs, parameters, provider_mapping_info)
|
|
58
58
|
response_format = parameters.get("response_format")
|
|
59
59
|
if isinstance(response_format, dict) and response_format.get("type") == "json_schema":
|
|
@@ -72,8 +72,8 @@ class TogetherTextToImageTask(TogetherTask):
|
|
|
72
72
|
super().__init__("text-to-image")
|
|
73
73
|
|
|
74
74
|
def _prepare_payload_as_dict(
|
|
75
|
-
self, inputs: Any, parameters:
|
|
76
|
-
) -> Optional[
|
|
75
|
+
self, inputs: Any, parameters: dict, provider_mapping_info: InferenceProviderMapping
|
|
76
|
+
) -> Optional[dict]:
|
|
77
77
|
mapped_model = provider_mapping_info.provider_id
|
|
78
78
|
parameters = filter_none(parameters)
|
|
79
79
|
if "num_inference_steps" in parameters:
|
|
@@ -83,6 +83,6 @@ class TogetherTextToImageTask(TogetherTask):
|
|
|
83
83
|
|
|
84
84
|
return {"prompt": inputs, "response_format": "base64", **parameters, "model": mapped_model}
|
|
85
85
|
|
|
86
|
-
def get_response(self, response: Union[bytes,
|
|
86
|
+
def get_response(self, response: Union[bytes, dict], request_params: Optional[RequestParameters] = None) -> Any:
|
|
87
87
|
response_dict = _as_dict(response)
|
|
88
88
|
return base64.b64decode(response_dict["data"][0]["b64_json"])
|