huggingface-hub 0.23.5__py3-none-any.whl → 0.24.1__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 +47 -15
- huggingface_hub/_commit_api.py +38 -8
- huggingface_hub/_inference_endpoints.py +11 -4
- huggingface_hub/_local_folder.py +22 -13
- huggingface_hub/_snapshot_download.py +12 -7
- huggingface_hub/_webhooks_server.py +3 -1
- huggingface_hub/commands/huggingface_cli.py +4 -3
- huggingface_hub/commands/repo_files.py +128 -0
- huggingface_hub/constants.py +12 -0
- huggingface_hub/file_download.py +127 -91
- huggingface_hub/hf_api.py +976 -341
- huggingface_hub/hf_file_system.py +30 -3
- huggingface_hub/inference/_client.py +408 -147
- huggingface_hub/inference/_common.py +25 -63
- huggingface_hub/inference/_generated/_async_client.py +425 -153
- huggingface_hub/inference/_generated/types/__init__.py +4 -1
- huggingface_hub/inference/_generated/types/chat_completion.py +41 -21
- huggingface_hub/inference/_generated/types/feature_extraction.py +23 -5
- huggingface_hub/inference/_generated/types/text_generation.py +29 -0
- huggingface_hub/lfs.py +11 -6
- huggingface_hub/repocard_data.py +3 -3
- huggingface_hub/repository.py +6 -6
- huggingface_hub/serialization/__init__.py +8 -3
- huggingface_hub/serialization/_base.py +13 -16
- huggingface_hub/serialization/_tensorflow.py +4 -3
- huggingface_hub/serialization/_torch.py +399 -22
- huggingface_hub/utils/__init__.py +0 -1
- huggingface_hub/utils/_errors.py +1 -1
- huggingface_hub/utils/_fixes.py +14 -3
- huggingface_hub/utils/_paths.py +17 -6
- huggingface_hub/utils/_subprocess.py +0 -1
- huggingface_hub/utils/_telemetry.py +9 -1
- huggingface_hub/utils/endpoint_helpers.py +2 -186
- huggingface_hub/utils/sha.py +36 -1
- huggingface_hub/utils/tqdm.py +0 -1
- {huggingface_hub-0.23.5.dist-info → huggingface_hub-0.24.1.dist-info}/METADATA +12 -9
- {huggingface_hub-0.23.5.dist-info → huggingface_hub-0.24.1.dist-info}/RECORD +41 -41
- huggingface_hub/serialization/_numpy.py +0 -68
- {huggingface_hub-0.23.5.dist-info → huggingface_hub-0.24.1.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.23.5.dist-info → huggingface_hub-0.24.1.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.23.5.dist-info → huggingface_hub-0.24.1.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-0.23.5.dist-info → huggingface_hub-0.24.1.dist-info}/top_level.txt +0 -0
|
@@ -34,7 +34,6 @@ from typing import (
|
|
|
34
34
|
Literal,
|
|
35
35
|
NoReturn,
|
|
36
36
|
Optional,
|
|
37
|
-
Set,
|
|
38
37
|
Union,
|
|
39
38
|
overload,
|
|
40
39
|
)
|
|
@@ -61,8 +60,6 @@ from ..utils import (
|
|
|
61
60
|
)
|
|
62
61
|
from ._generated.types import (
|
|
63
62
|
ChatCompletionStreamOutput,
|
|
64
|
-
ChatCompletionStreamOutputChoice,
|
|
65
|
-
ChatCompletionStreamOutputDelta,
|
|
66
63
|
TextGenerationStreamOutput,
|
|
67
64
|
)
|
|
68
65
|
|
|
@@ -271,7 +268,10 @@ def _stream_text_generation_response(
|
|
|
271
268
|
"""Used in `InferenceClient.text_generation`."""
|
|
272
269
|
# Parse ServerSentEvents
|
|
273
270
|
for byte_payload in bytes_output_as_lines:
|
|
274
|
-
|
|
271
|
+
try:
|
|
272
|
+
output = _format_text_generation_stream_output(byte_payload, details)
|
|
273
|
+
except StopIteration:
|
|
274
|
+
break
|
|
275
275
|
if output is not None:
|
|
276
276
|
yield output
|
|
277
277
|
|
|
@@ -282,7 +282,10 @@ async def _async_stream_text_generation_response(
|
|
|
282
282
|
"""Used in `AsyncInferenceClient.text_generation`."""
|
|
283
283
|
# Parse ServerSentEvents
|
|
284
284
|
async for byte_payload in bytes_output_as_lines:
|
|
285
|
-
|
|
285
|
+
try:
|
|
286
|
+
output = _format_text_generation_stream_output(byte_payload, details)
|
|
287
|
+
except StopIteration:
|
|
288
|
+
break
|
|
286
289
|
if output is not None:
|
|
287
290
|
yield output
|
|
288
291
|
|
|
@@ -293,6 +296,9 @@ def _format_text_generation_stream_output(
|
|
|
293
296
|
if not byte_payload.startswith(b"data:"):
|
|
294
297
|
return None # empty line
|
|
295
298
|
|
|
299
|
+
if byte_payload == b"data: [DONE]":
|
|
300
|
+
raise StopIteration("[DONE] signal received.")
|
|
301
|
+
|
|
296
302
|
# Decode payload
|
|
297
303
|
payload = byte_payload.decode("utf-8")
|
|
298
304
|
json_payload = json.loads(payload.lstrip("data:").rstrip("/n"))
|
|
@@ -306,74 +312,41 @@ def _format_text_generation_stream_output(
|
|
|
306
312
|
return output.token.text if not details else output
|
|
307
313
|
|
|
308
314
|
|
|
309
|
-
def
|
|
310
|
-
item: TextGenerationStreamOutput, created: int
|
|
311
|
-
) -> ChatCompletionStreamOutput:
|
|
312
|
-
if item.details is None:
|
|
313
|
-
# new token generated => return delta
|
|
314
|
-
return ChatCompletionStreamOutput(
|
|
315
|
-
# explicitly set 'dummy' values to reduce expectations from users
|
|
316
|
-
id="dummy",
|
|
317
|
-
model="dummy",
|
|
318
|
-
object="dummy",
|
|
319
|
-
system_fingerprint="dummy",
|
|
320
|
-
choices=[
|
|
321
|
-
ChatCompletionStreamOutputChoice(
|
|
322
|
-
delta=ChatCompletionStreamOutputDelta(
|
|
323
|
-
role="assistant",
|
|
324
|
-
content=item.token.text,
|
|
325
|
-
),
|
|
326
|
-
finish_reason=None,
|
|
327
|
-
index=0,
|
|
328
|
-
)
|
|
329
|
-
],
|
|
330
|
-
created=created,
|
|
331
|
-
)
|
|
332
|
-
else:
|
|
333
|
-
# generation is completed => return finish reason
|
|
334
|
-
return ChatCompletionStreamOutput(
|
|
335
|
-
# explicitly set 'dummy' values to reduce expectations from users
|
|
336
|
-
id="dummy",
|
|
337
|
-
model="dummy",
|
|
338
|
-
object="dummy",
|
|
339
|
-
system_fingerprint="dummy",
|
|
340
|
-
choices=[
|
|
341
|
-
ChatCompletionStreamOutputChoice(
|
|
342
|
-
delta=ChatCompletionStreamOutputDelta(role="assistant"),
|
|
343
|
-
finish_reason=item.details.finish_reason,
|
|
344
|
-
index=0,
|
|
345
|
-
)
|
|
346
|
-
],
|
|
347
|
-
created=created,
|
|
348
|
-
)
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
def _stream_chat_completion_response_from_bytes(
|
|
315
|
+
def _stream_chat_completion_response(
|
|
352
316
|
bytes_lines: Iterable[bytes],
|
|
353
317
|
) -> Iterable[ChatCompletionStreamOutput]:
|
|
354
318
|
"""Used in `InferenceClient.chat_completion` if model is served with TGI."""
|
|
355
319
|
for item in bytes_lines:
|
|
356
|
-
|
|
320
|
+
try:
|
|
321
|
+
output = _format_chat_completion_stream_output(item)
|
|
322
|
+
except StopIteration:
|
|
323
|
+
break
|
|
357
324
|
if output is not None:
|
|
358
325
|
yield output
|
|
359
326
|
|
|
360
327
|
|
|
361
|
-
async def
|
|
328
|
+
async def _async_stream_chat_completion_response(
|
|
362
329
|
bytes_lines: AsyncIterable[bytes],
|
|
363
330
|
) -> AsyncIterable[ChatCompletionStreamOutput]:
|
|
364
331
|
"""Used in `AsyncInferenceClient.chat_completion`."""
|
|
365
332
|
async for item in bytes_lines:
|
|
366
|
-
|
|
333
|
+
try:
|
|
334
|
+
output = _format_chat_completion_stream_output(item)
|
|
335
|
+
except StopIteration:
|
|
336
|
+
break
|
|
367
337
|
if output is not None:
|
|
368
338
|
yield output
|
|
369
339
|
|
|
370
340
|
|
|
371
|
-
def
|
|
341
|
+
def _format_chat_completion_stream_output(
|
|
372
342
|
byte_payload: bytes,
|
|
373
343
|
) -> Optional[ChatCompletionStreamOutput]:
|
|
374
344
|
if not byte_payload.startswith(b"data:"):
|
|
375
345
|
return None # empty line
|
|
376
346
|
|
|
347
|
+
if byte_payload == b"data: [DONE]":
|
|
348
|
+
raise StopIteration("[DONE] signal received.")
|
|
349
|
+
|
|
377
350
|
# Decode payload
|
|
378
351
|
payload = byte_payload.decode("utf-8")
|
|
379
352
|
json_payload = json.loads(payload.lstrip("data:").rstrip("/n"))
|
|
@@ -415,17 +388,6 @@ def _get_unsupported_text_generation_kwargs(model: Optional[str]) -> List[str]:
|
|
|
415
388
|
return _UNSUPPORTED_TEXT_GENERATION_KWARGS.get(model, [])
|
|
416
389
|
|
|
417
390
|
|
|
418
|
-
_NON_CHAT_COMPLETION_SERVER: Set[str] = set()
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
def _set_as_non_chat_completion_server(model: str) -> None:
|
|
422
|
-
_NON_CHAT_COMPLETION_SERVER.add(model)
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
def _is_chat_completion_server(model: str) -> bool:
|
|
426
|
-
return model not in _NON_CHAT_COMPLETION_SERVER
|
|
427
|
-
|
|
428
|
-
|
|
429
391
|
# TEXT GENERATION ERRORS
|
|
430
392
|
# ----------------------
|
|
431
393
|
# Text-generation errors are parsed separately to handle as much as possible the errors returned by the text generation
|