huggingface-hub 0.32.0rc1__py3-none-any.whl → 0.32.2__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.

@@ -46,7 +46,7 @@ import sys
46
46
  from typing import TYPE_CHECKING
47
47
 
48
48
 
49
- __version__ = "0.32.0.rc1"
49
+ __version__ = "0.32.2"
50
50
 
51
51
  # Alphabetical order of definitions is ensured in tests
52
52
  # WARNING: any comment added in this dictionary definition will be lost when
@@ -1,6 +1,6 @@
1
1
  import os
2
2
  from pathlib import Path
3
- from typing import Dict, List, Literal, Optional, Union
3
+ from typing import Dict, Iterable, List, Literal, Optional, Union
4
4
 
5
5
  import requests
6
6
  from tqdm.auto import tqdm as base_tqdm
@@ -15,13 +15,15 @@ from .errors import (
15
15
  RevisionNotFoundError,
16
16
  )
17
17
  from .file_download import REGEX_COMMIT_HASH, hf_hub_download, repo_folder_name
18
- from .hf_api import DatasetInfo, HfApi, ModelInfo, SpaceInfo
18
+ from .hf_api import DatasetInfo, HfApi, ModelInfo, RepoFile, SpaceInfo
19
19
  from .utils import OfflineModeIsEnabled, filter_repo_objects, logging, validate_hf_hub_args
20
20
  from .utils import tqdm as hf_tqdm
21
21
 
22
22
 
23
23
  logger = logging.get_logger(__name__)
24
24
 
25
+ VERY_LARGE_REPO_THRESHOLD = 50000 # After this limit, we don't consider `repo_info.siblings` to be reliable enough
26
+
25
27
 
26
28
  @validate_hf_hub_args
27
29
  def snapshot_download(
@@ -145,20 +147,22 @@ def snapshot_download(
145
147
 
146
148
  storage_folder = os.path.join(cache_dir, repo_folder_name(repo_id=repo_id, repo_type=repo_type))
147
149
 
150
+ api = HfApi(
151
+ library_name=library_name,
152
+ library_version=library_version,
153
+ user_agent=user_agent,
154
+ endpoint=endpoint,
155
+ headers=headers,
156
+ token=token,
157
+ )
158
+
148
159
  repo_info: Union[ModelInfo, DatasetInfo, SpaceInfo, None] = None
149
160
  api_call_error: Optional[Exception] = None
150
161
  if not local_files_only:
151
162
  # try/except logic to handle different errors => taken from `hf_hub_download`
152
163
  try:
153
164
  # if we have internet connection we want to list files to download
154
- api = HfApi(
155
- library_name=library_name,
156
- library_version=library_version,
157
- user_agent=user_agent,
158
- endpoint=endpoint,
159
- headers=headers,
160
- )
161
- repo_info = api.repo_info(repo_id=repo_id, repo_type=repo_type, revision=revision, token=token)
165
+ repo_info = api.repo_info(repo_id=repo_id, repo_type=repo_type, revision=revision)
162
166
  except (requests.exceptions.SSLError, requests.exceptions.ProxyError):
163
167
  # Actually raise for those subclasses of ConnectionError
164
168
  raise
@@ -251,13 +255,31 @@ def snapshot_download(
251
255
  # => let's download the files!
252
256
  assert repo_info.sha is not None, "Repo info returned from server must have a revision sha."
253
257
  assert repo_info.siblings is not None, "Repo info returned from server must have a siblings list."
254
- filtered_repo_files = list(
255
- filter_repo_objects(
256
- items=[f.rfilename for f in repo_info.siblings],
257
- allow_patterns=allow_patterns,
258
- ignore_patterns=ignore_patterns,
258
+
259
+ # Corner case: on very large repos, the siblings list in `repo_info` might not contain all files.
260
+ # In that case, we need to use the `list_repo_tree` method to prevent caching issues.
261
+ repo_files: Iterable[str] = [f.rfilename for f in repo_info.siblings]
262
+ has_many_files = len(repo_info.siblings) > VERY_LARGE_REPO_THRESHOLD
263
+ if has_many_files:
264
+ logger.info("The repo has more than 50,000 files. Using `list_repo_tree` to ensure all files are listed.")
265
+ repo_files = (
266
+ f.rfilename
267
+ for f in api.list_repo_tree(repo_id=repo_id, recursive=True, revision=revision, repo_type=repo_type)
268
+ if isinstance(f, RepoFile)
259
269
  )
270
+
271
+ filtered_repo_files: Iterable[str] = filter_repo_objects(
272
+ items=repo_files,
273
+ allow_patterns=allow_patterns,
274
+ ignore_patterns=ignore_patterns,
260
275
  )
276
+
277
+ if not has_many_files:
278
+ filtered_repo_files = list(filtered_repo_files)
279
+ tqdm_desc = f"Fetching {len(filtered_repo_files)} files"
280
+ else:
281
+ tqdm_desc = "Fetching ... files"
282
+
261
283
  commit_hash = repo_info.sha
262
284
  snapshot_folder = os.path.join(storage_folder, "snapshots", commit_hash)
263
285
  # if passed revision is not identical to commit_hash
@@ -305,7 +327,7 @@ def snapshot_download(
305
327
  thread_map(
306
328
  _inner_hf_hub_download,
307
329
  filtered_repo_files,
308
- desc=f"Fetching {len(filtered_repo_files)} files",
330
+ desc=tqdm_desc,
309
331
  max_workers=max_workers,
310
332
  # User can use its own tqdm class or the default one from `huggingface_hub.utils`
311
333
  tqdm_class=tqdm_class or hf_tqdm,
@@ -20,7 +20,7 @@ class Agent(MCPClient):
20
20
  </Tip>
21
21
 
22
22
  Args:
23
- model (`str`):
23
+ model (`str`, *optional*):
24
24
  The model to run inference with. Can be a model id hosted on the Hugging Face Hub, e.g. `meta-llama/Meta-Llama-3-8B-Instruct`
25
25
  or a URL to a deployed Inference Endpoint or other local or remote endpoint.
26
26
  servers (`Iterable[Dict]`):
@@ -28,6 +28,8 @@ class Agent(MCPClient):
28
28
  provider (`str`, *optional*):
29
29
  Name of the provider to use for inference. Defaults to "auto" i.e. the first of the providers available for the model, sorted by the user's order in https://hf.co/settings/inference-providers.
30
30
  If model is a URL or `base_url` is passed, then `provider` is not used.
31
+ base_url (`str`, *optional*):
32
+ The base URL to run inference. Defaults to None.
31
33
  api_key (`str`, *optional*):
32
34
  Token to use for authentication. Will default to the locally Hugging Face saved token if not provided. You can also use your own provider API key to interact directly with the provider's service.
33
35
  prompt (`str`, *optional*):
@@ -37,13 +39,14 @@ class Agent(MCPClient):
37
39
  def __init__(
38
40
  self,
39
41
  *,
40
- model: str,
42
+ model: Optional[str] = None,
41
43
  servers: Iterable[Dict],
42
44
  provider: Optional[PROVIDER_OR_POLICY_T] = None,
45
+ base_url: Optional[str] = None,
43
46
  api_key: Optional[str] = None,
44
47
  prompt: Optional[str] = None,
45
48
  ):
46
- super().__init__(model=model, provider=provider, api_key=api_key)
49
+ super().__init__(model=model, provider=provider, base_url=base_url, api_key=api_key)
47
50
  self._servers_cfg = list(servers)
48
51
  self.messages: List[Union[Dict, ChatCompletionInputMessage]] = [
49
52
  {"role": "system", "content": prompt or DEFAULT_SYSTEM_PROMPT}
@@ -1,6 +1,7 @@
1
1
  import asyncio
2
2
  import os
3
3
  import signal
4
+ import traceback
4
5
  from functools import partial
5
6
  from typing import Any, Dict, List, Optional
6
7
 
@@ -63,11 +64,17 @@ async def run_agent(
63
64
  os._exit(130)
64
65
 
65
66
  try:
66
- loop.add_signal_handler(signal.SIGINT, _sigint_handler)
67
-
67
+ sigint_registered_in_loop = False
68
+ try:
69
+ loop.add_signal_handler(signal.SIGINT, _sigint_handler)
70
+ sigint_registered_in_loop = True
71
+ except (AttributeError, NotImplementedError):
72
+ # Windows (or any loop that doesn't support it) : fall back to sync
73
+ signal.signal(signal.SIGINT, lambda *_: _sigint_handler())
68
74
  async with Agent(
69
- provider=config["provider"],
70
- model=config["model"],
75
+ provider=config.get("provider"),
76
+ model=config.get("model"),
77
+ base_url=config.get("endpointUrl"),
71
78
  servers=servers,
72
79
  prompt=prompt,
73
80
  ) as agent:
@@ -118,13 +125,22 @@ async def run_agent(
118
125
  print()
119
126
 
120
127
  except Exception as e:
121
- print(f"\n[bold red]Error during agent run: {e}[/bold red]", flush=True)
128
+ tb_str = traceback.format_exc()
129
+ print(f"\n[bold red]Error during agent run: {e}\n{tb_str}[/bold red]", flush=True)
122
130
  first_sigint = True # Allow graceful interrupt for the next command
123
131
 
132
+ except Exception as e:
133
+ tb_str = traceback.format_exc()
134
+ print(f"\n[bold red]An unexpected error occurred: {e}\n{tb_str}[/bold red]", flush=True)
135
+ raise e
136
+
124
137
  finally:
125
- if loop and not loop.is_closed():
126
- loop.remove_signal_handler(signal.SIGINT)
127
- elif original_sigint_handler:
138
+ if sigint_registered_in_loop:
139
+ try:
140
+ loop.remove_signal_handler(signal.SIGINT)
141
+ except (AttributeError, NotImplementedError):
142
+ pass
143
+ else:
128
144
  signal.signal(signal.SIGINT, original_sigint_handler)
129
145
 
130
146
 
@@ -69,6 +69,8 @@ class MCPClient:
69
69
  provider (`str`, *optional*):
70
70
  Name of the provider to use for inference. Defaults to "auto" i.e. the first of the providers available for the model, sorted by the user's order in https://hf.co/settings/inference-providers.
71
71
  If model is a URL or `base_url` is passed, then `provider` is not used.
72
+ base_url (`str`, *optional*):
73
+ The base URL to run inference. Defaults to None.
72
74
  api_key (`str`, `optional`):
73
75
  Token to use for authentication. Will default to the locally Hugging Face saved token if not provided. You can also use your own provider API key to interact directly with the provider's service.
74
76
  """
@@ -76,17 +78,25 @@ class MCPClient:
76
78
  def __init__(
77
79
  self,
78
80
  *,
79
- model: str,
81
+ model: Optional[str] = None,
80
82
  provider: Optional[PROVIDER_OR_POLICY_T] = None,
83
+ base_url: Optional[str] = None,
81
84
  api_key: Optional[str] = None,
82
85
  ):
83
86
  # Initialize MCP sessions as a dictionary of ClientSession objects
84
87
  self.sessions: Dict[ToolName, "ClientSession"] = {}
85
88
  self.exit_stack = AsyncExitStack()
86
89
  self.available_tools: List[ChatCompletionInputTool] = []
87
-
88
- # Initialize the AsyncInferenceClient
89
- self.client = AsyncInferenceClient(model=model, provider=provider, api_key=api_key)
90
+ # To be able to send the model in the payload if `base_url` is provided
91
+ if model is None and base_url is None:
92
+ raise ValueError("At least one of `model` or `base_url` should be set in `MCPClient`.")
93
+ self.payload_model = model
94
+ self.client = AsyncInferenceClient(
95
+ model=None if base_url is not None else model,
96
+ provider=provider,
97
+ api_key=api_key,
98
+ base_url=base_url,
99
+ )
90
100
 
91
101
  async def __aenter__(self):
92
102
  """Enter the context manager"""
@@ -244,6 +254,7 @@ class MCPClient:
244
254
 
245
255
  # Create the streaming request
246
256
  response = await self.client.chat.completions.create(
257
+ model=self.payload_model,
247
258
  messages=messages,
248
259
  tools=tools,
249
260
  tool_choice="auto",
@@ -246,7 +246,7 @@ def save_torch_state_dict(
246
246
  shared_tensors_to_discard=shared_tensors_to_discard,
247
247
  )
248
248
  else:
249
- from torch import save as save_file_fn # type: ignore[assignment]
249
+ from torch import save as save_file_fn # type: ignore[assignment, no-redef]
250
250
 
251
251
  logger.warning(
252
252
  "You are using unsafe serialization. Due to security reasons, it is recommended not to load "
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: huggingface-hub
3
- Version: 0.32.0rc1
3
+ Version: 0.32.2
4
4
  Summary: Client library to download and publish models, datasets and other repos on the huggingface.co hub
5
5
  Home-page: https://github.com/huggingface/huggingface_hub
6
6
  Author: Hugging Face, Inc.
@@ -1,11 +1,11 @@
1
- huggingface_hub/__init__.py,sha256=YkOYKjWB2DkIuauxhRnt48FZYg296N2BWwxV2FKVaj4,50648
1
+ huggingface_hub/__init__.py,sha256=j0CPc82aFQA-FV3ew00Ukp6u4v-Lz3cBrH-K33Z50yE,50644
2
2
  huggingface_hub/_commit_api.py,sha256=ZbmuIhFdF8B3F_cvGtxorka7MmIQOk8oBkCtYltnCvI,39456
3
3
  huggingface_hub/_commit_scheduler.py,sha256=tfIoO1xWHjTJ6qy6VS6HIoymDycFPg0d6pBSZprrU2U,14679
4
4
  huggingface_hub/_inference_endpoints.py,sha256=qXR0utAYRaEWTI8EXzAsDpVDcYpp8bJPEBbcOxRS52E,17413
5
5
  huggingface_hub/_local_folder.py,sha256=7Uce_z51D7ZZ58GF7eUOtcq1cCuYQMOEF-W4p85iQTo,16885
6
6
  huggingface_hub/_login.py,sha256=ssf4viT5BhHI2ZidnSuAZcrwSxzaLOrf8xgRVKuvu_A,20298
7
7
  huggingface_hub/_oauth.py,sha256=YNbSSZCNZLiCqwMoYboSAfI3XjEsbyAADJcwgRAdhBc,18802
8
- huggingface_hub/_snapshot_download.py,sha256=RqhfsESBHwXAoZxVvw68W7vGhmXSbl7RoEFOPLvw3Ls,15186
8
+ huggingface_hub/_snapshot_download.py,sha256=5BvLNm_1DgdBNXNWOP8omK-9unIyqNSVpDNmxfClxFk,16078
9
9
  huggingface_hub/_space_api.py,sha256=jb6rF8qLtjaNU12D-8ygAPM26xDiHCu8CHXHowhGTmg,5470
10
10
  huggingface_hub/_tensorboard_logger.py,sha256=ZkYcAUiRC8RGL214QUYtp58O8G5tn-HF6DCWha9imcA,8358
11
11
  huggingface_hub/_upload_large_folder.py,sha256=elY5Rv2YVJECVpdZ9PM1zdO8kG-jmi8DifLOa7aC3EU,24178
@@ -81,10 +81,10 @@ huggingface_hub/inference/_generated/types/zero_shot_classification.py,sha256=BA
81
81
  huggingface_hub/inference/_generated/types/zero_shot_image_classification.py,sha256=8J9n6VqFARkWvPfAZNWEG70AlrMGldU95EGQQwn06zI,1487
82
82
  huggingface_hub/inference/_generated/types/zero_shot_object_detection.py,sha256=GUd81LIV7oEbRWayDlAVgyLmY596r1M3AW0jXDp1yTA,1630
83
83
  huggingface_hub/inference/_mcp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
84
- huggingface_hub/inference/_mcp/agent.py,sha256=RDpqy2rcVKy0euIK43OAAczLlx0UH1QIACHMFjTItq0,4077
85
- huggingface_hub/inference/_mcp/cli.py,sha256=7vvP0TcSWOR2GBU8ApG7zpdtGI4cnB_R1ehr6XrZMdo,5177
84
+ huggingface_hub/inference/_mcp/agent.py,sha256=azX9_lsFjNlgsEvRYdKgsmOmpNReWIcbuMeIVWc852k,4264
85
+ huggingface_hub/inference/_mcp/cli.py,sha256=q7WUlc7K9cHffKnS8uVydqM7IGxDz2gnwoNKkiRF5GU,5873
86
86
  huggingface_hub/inference/_mcp/constants.py,sha256=tE_V6qcvsmvVoJa4eg04jhoTR2Cx1cNHieY2ENrm1_M,2511
87
- huggingface_hub/inference/_mcp/mcp_client.py,sha256=MwoovV2UTf7F8rxxQucAd4WSnIiJ71wx09QCrXDrP0Q,13477
87
+ huggingface_hub/inference/_mcp/mcp_client.py,sha256=HUDkEURrWeQ9AY7W4_H4jca0BM12rKPbjdP4vNaXiwc,13998
88
88
  huggingface_hub/inference/_mcp/utils.py,sha256=K7rr4FxCh9OYWwYNlnvQraNLy9y3z-5yVMBIaoCQMjA,4052
89
89
  huggingface_hub/inference/_providers/__init__.py,sha256=IrLTMERrbRuPiVdBQEMK9TMvXrsGId4-u2ucMkG-vTU,7671
90
90
  huggingface_hub/inference/_providers/_common.py,sha256=Octgz-PbHw62iW3Oa8rF7rxvBJR0ZmL4ouv3NoX-weE,10131
@@ -106,7 +106,7 @@ huggingface_hub/serialization/__init__.py,sha256=kn-Fa-m4FzMnN8lNsF-SwFcfzug4Cuc
106
106
  huggingface_hub/serialization/_base.py,sha256=Df3GwGR9NzeK_SD75prXLucJAzPiNPgHbgXSw-_LTk8,8126
107
107
  huggingface_hub/serialization/_dduf.py,sha256=s42239rLiHwaJE36QDEmS5GH7DSmQ__BffiHJO5RjIg,15424
108
108
  huggingface_hub/serialization/_tensorflow.py,sha256=zHOvEMg-JHC55Fm4roDT3LUCDO5zB9qtXZffG065RAM,3625
109
- huggingface_hub/serialization/_torch.py,sha256=hJglq5F56s3k06GfLuYKQV4bSSjXQLuk1CC9l1M3Fmo,45191
109
+ huggingface_hub/serialization/_torch.py,sha256=jpBmuSZJymMpvLcDcMaNxDu_fE5VkY_pAVH8e8stYIo,45201
110
110
  huggingface_hub/templates/datasetcard_template.md,sha256=W-EMqR6wndbrnZorkVv56URWPG49l7MATGeI015kTvs,5503
111
111
  huggingface_hub/templates/modelcard_template.md,sha256=4AqArS3cqdtbit5Bo-DhjcnDFR-pza5hErLLTPM4Yuc,6870
112
112
  huggingface_hub/utils/__init__.py,sha256=ORfVkn5D0wuLIq12jjhTzn5_c4F8fRPxB7TG-iednuQ,3722
@@ -137,9 +137,9 @@ huggingface_hub/utils/insecure_hashlib.py,sha256=iAaepavFZ5Dhfa5n8KozRfQprKmvcjS
137
137
  huggingface_hub/utils/logging.py,sha256=0A8fF1yh3L9Ka_bCDX2ml4U5Ht0tY8Dr3JcbRvWFuwo,4909
138
138
  huggingface_hub/utils/sha.py,sha256=OFnNGCba0sNcT2gUwaVCJnldxlltrHHe0DS_PCpV3C4,2134
139
139
  huggingface_hub/utils/tqdm.py,sha256=xAKcyfnNHsZ7L09WuEM5Ew5-MDhiahLACbbN2zMmcLs,10671
140
- huggingface_hub-0.32.0rc1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
141
- huggingface_hub-0.32.0rc1.dist-info/METADATA,sha256=vJ0eUDTcx6H_mI1vNATLw1wgnIl0BeHmg-yVvYNwahY,14780
142
- huggingface_hub-0.32.0rc1.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
143
- huggingface_hub-0.32.0rc1.dist-info/entry_points.txt,sha256=uelw0-fu0kd-CxIuOsR1bsjLIFnAaMQ6AIqluJYDhQw,184
144
- huggingface_hub-0.32.0rc1.dist-info/top_level.txt,sha256=8KzlQJAY4miUvjAssOAJodqKOw3harNzuiwGQ9qLSSk,16
145
- huggingface_hub-0.32.0rc1.dist-info/RECORD,,
140
+ huggingface_hub-0.32.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
141
+ huggingface_hub-0.32.2.dist-info/METADATA,sha256=w2Df9xLc5FhDmwO11yIxMDiHc-i7aqLvXFRzRvzgI_E,14777
142
+ huggingface_hub-0.32.2.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
143
+ huggingface_hub-0.32.2.dist-info/entry_points.txt,sha256=uelw0-fu0kd-CxIuOsR1bsjLIFnAaMQ6AIqluJYDhQw,184
144
+ huggingface_hub-0.32.2.dist-info/top_level.txt,sha256=8KzlQJAY4miUvjAssOAJodqKOw3harNzuiwGQ9qLSSk,16
145
+ huggingface_hub-0.32.2.dist-info/RECORD,,