evalstate HF Staff commited on
Commit
4180f47
·
verified ·
1 Parent(s): a87feb2

Upload 2 files

Browse files
Files changed (2) hide show
  1. hf_api_tool.py +224 -0
  2. hf_hub_community.md +355 -0
hf_api_tool.py ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import os
5
+ import re
6
+ from pathlib import Path
7
+ from typing import Any
8
+ from urllib.error import HTTPError, URLError
9
+ from urllib.parse import urlencode
10
+ from urllib.request import Request, urlopen
11
+
12
+ DEFAULT_MAX_RESULTS = 20
13
+ DEFAULT_TIMEOUT_SEC = 30
14
+
15
+ # ---------------------------------------------------------------------------
16
+ # Endpoint allowlist (regex patterns)
17
+ # Only endpoints matching these patterns are permitted.
18
+ # ---------------------------------------------------------------------------
19
+ ALLOWED_ENDPOINT_PATTERNS: list[str] = [
20
+ # User data
21
+ r"^/whoami-v2$",
22
+ r"^/users/[^/]+/overview$",
23
+ r"^/users/[^/]+/likes$",
24
+ r"^/users/[^/]+/followers$",
25
+ r"^/users/[^/]+/following$",
26
+ # Organizations
27
+ r"^/organizations/[^/]+/overview$",
28
+ r"^/organizations/[^/]+/members$",
29
+ r"^/organizations/[^/]+/followers$",
30
+ # Discussions & PRs (repo_type: models, datasets, spaces)
31
+ r"^/(models|datasets|spaces)/[^/]+/[^/]+/discussions$",
32
+ r"^/(models|datasets|spaces)/[^/]+/[^/]+/discussions/\d+$",
33
+ r"^/(models|datasets|spaces)/[^/]+/[^/]+/discussions/\d+/comment$",
34
+ r"^/(models|datasets|spaces)/[^/]+/[^/]+/discussions/\d+/comment/[^/]+/edit$",
35
+ r"^/(models|datasets|spaces)/[^/]+/[^/]+/discussions/\d+/comment/[^/]+/hide$",
36
+ r"^/(models|datasets|spaces)/[^/]+/[^/]+/discussions/\d+/status$",
37
+ # Access requests (gated repos)
38
+ r"^/(models|datasets|spaces)/[^/]+/[^/]+/user-access-request/pending$",
39
+ r"^/(models|datasets|spaces)/[^/]+/[^/]+/user-access-request/accepted$",
40
+ r"^/(models|datasets|spaces)/[^/]+/[^/]+/user-access-request/rejected$",
41
+ r"^/(models|datasets|spaces)/[^/]+/[^/]+/user-access-request/handle$",
42
+ r"^/(models|datasets|spaces)/[^/]+/[^/]+/user-access-request/grant$",
43
+ # Collections
44
+ r"^/collections$",
45
+ r"^/collections/[^/]+$",
46
+ r"^/collections/[^/]+/items$",
47
+ # Auth check
48
+ r"^/(models|datasets|spaces)/[^/]+/[^/]+/auth-check$",
49
+ ]
50
+
51
+ _COMPILED_PATTERNS: list[re.Pattern[str]] = [
52
+ re.compile(p) for p in ALLOWED_ENDPOINT_PATTERNS
53
+ ]
54
+
55
+
56
+ def _is_endpoint_allowed(endpoint: str) -> bool:
57
+ """Return True if endpoint matches any allowed pattern."""
58
+ return any(pattern.match(endpoint) for pattern in _COMPILED_PATTERNS)
59
+
60
+
61
+ def _load_token() -> str | None:
62
+ # Check for request-scoped token first (when running as MCP server)
63
+ # This allows clients to pass their own HF token via Authorization header
64
+ try:
65
+ from fast_agent.mcp.auth.context import request_bearer_token
66
+
67
+ ctx_token = request_bearer_token.get()
68
+ if ctx_token:
69
+ return ctx_token
70
+ except ImportError:
71
+ # fast_agent.mcp.auth.context not available
72
+ pass
73
+
74
+ # Fall back to HF_TOKEN environment variable
75
+ token = os.getenv("HF_TOKEN")
76
+ if token:
77
+ return token
78
+
79
+ # Fall back to cached huggingface token file
80
+ token_path = Path.home() / ".cache" / "huggingface" / "token"
81
+ if token_path.exists():
82
+ token_value = token_path.read_text(encoding="utf-8").strip()
83
+ return token_value or None
84
+
85
+ return None
86
+
87
+
88
+ def _max_results_from_env() -> int:
89
+ raw = os.getenv("HF_MAX_RESULTS")
90
+ if not raw:
91
+ return DEFAULT_MAX_RESULTS
92
+ try:
93
+ value = int(raw)
94
+ except ValueError:
95
+ return DEFAULT_MAX_RESULTS
96
+ return value if value > 0 else DEFAULT_MAX_RESULTS
97
+
98
+
99
+ def _normalize_endpoint(endpoint: str) -> str:
100
+ """Normalize and validate an endpoint path.
101
+
102
+ Checks:
103
+ - Must be a relative path (not a full URL)
104
+ - Must be non-empty
105
+ - No path traversal sequences (..)
106
+ - Must match the endpoint allowlist
107
+ """
108
+ if endpoint.startswith("http://") or endpoint.startswith("https://"):
109
+ raise ValueError("Endpoint must be a path relative to /api, not a full URL.")
110
+ endpoint = endpoint.strip()
111
+ if not endpoint:
112
+ raise ValueError("Endpoint must be a non-empty string.")
113
+
114
+ # Path traversal protection
115
+ if ".." in endpoint:
116
+ raise ValueError("Path traversal sequences (..) are not allowed in endpoints.")
117
+
118
+ if not endpoint.startswith("/"):
119
+ endpoint = f"/{endpoint}"
120
+
121
+ # Allowlist validation
122
+ if not _is_endpoint_allowed(endpoint):
123
+ raise ValueError(
124
+ f"Endpoint '{endpoint}' is not in the allowed list. "
125
+ "See ALLOWED_ENDPOINT_PATTERNS for permitted endpoints."
126
+ )
127
+
128
+ return endpoint
129
+
130
+
131
+ def _normalize_params(params: dict[str, Any] | None) -> dict[str, Any]:
132
+ if not params:
133
+ return {}
134
+ normalized: dict[str, Any] = {}
135
+ for key, value in params.items():
136
+ if value is None:
137
+ continue
138
+ if isinstance(value, (list, tuple)):
139
+ normalized[key] = [str(item) for item in value]
140
+ else:
141
+ normalized[key] = str(value)
142
+ return normalized
143
+
144
+
145
+ def _build_url(endpoint: str, params: dict[str, Any] | None) -> str:
146
+ base = os.getenv("HF_ENDPOINT", "https://huggingface.co").rstrip("/")
147
+ url = f"{base}/api{_normalize_endpoint(endpoint)}"
148
+ normalized_params = _normalize_params(params)
149
+ if normalized_params:
150
+ url = f"{url}?{urlencode(normalized_params, doseq=True)}"
151
+ return url
152
+
153
+
154
+ def hf_api_request(
155
+ endpoint: str,
156
+ method: str = "GET",
157
+ params: dict[str, Any] | None = None,
158
+ json_body: dict[str, Any] | None = None,
159
+ max_results: int | None = None,
160
+ offset: int | None = None,
161
+ ) -> dict[str, Any]:
162
+ """
163
+ Call the Hugging Face Hub API (GET/POST only).
164
+
165
+ Args:
166
+ endpoint: API endpoint relative to /api (e.g. "/whoami-v2").
167
+ method: HTTP method (GET or POST).
168
+ params: Optional query parameters.
169
+ json_body: Optional JSON payload for POST requests.
170
+ max_results: Max results when response is a list (defaults to HF_MAX_RESULTS).
171
+ offset: Client-side offset when response is a list (defaults to 0).
172
+
173
+ Returns:
174
+ A dict with the response data and request metadata.
175
+ """
176
+ method_upper = method.upper()
177
+ if method_upper not in {"GET", "POST"}:
178
+ raise ValueError("Only GET and POST are allowed for hf_api_request.")
179
+
180
+ if method_upper == "GET" and json_body is not None:
181
+ raise ValueError("GET requests do not accept json_body.")
182
+
183
+ url = _build_url(endpoint, params)
184
+
185
+ headers = {
186
+ "Accept": "application/json",
187
+ }
188
+ token = _load_token()
189
+ if token:
190
+ headers["Authorization"] = f"Bearer {token}"
191
+
192
+ data = None
193
+ if method_upper == "POST":
194
+ headers["Content-Type"] = "application/json"
195
+ data = json.dumps(json_body or {}).encode("utf-8")
196
+
197
+ request = Request(url, headers=headers, data=data, method=method_upper)
198
+
199
+ try:
200
+ with urlopen(request, timeout=DEFAULT_TIMEOUT_SEC) as response:
201
+ raw = response.read()
202
+ status_code = response.status
203
+ except HTTPError as exc:
204
+ error_body = exc.read().decode("utf-8", errors="replace")
205
+ raise RuntimeError(f"HF API error {exc.code} for {url}: {error_body}") from exc
206
+ except URLError as exc:
207
+ raise RuntimeError(f"HF API request failed for {url}: {exc}") from exc
208
+
209
+ try:
210
+ payload = json.loads(raw)
211
+ except json.JSONDecodeError:
212
+ payload = raw.decode("utf-8", errors="replace")
213
+
214
+ if isinstance(payload, list):
215
+ limit = max_results if max_results is not None else _max_results_from_env()
216
+ start = max(offset or 0, 0)
217
+ end = start + max(limit, 0)
218
+ payload = payload[start:end]
219
+
220
+ return {
221
+ "url": url,
222
+ "status": status_code,
223
+ "data": payload,
224
+ }
hf_hub_community.md ADDED
@@ -0,0 +1,355 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ function_tools:
3
+ - hf_api_tool.py:hf_api_request
4
+ model: gpt-oss
5
+ description: "Query Hugging Face community features: user/org profiles, followers, repo discussions, pull requests, comments, access requests, and collections. Use for people lookups and repo collaboration—not for model/dataset search."
6
+ ---
7
+ Hugging Face Hub Methods: How to Call (User/Org Focus)
8
+ ======================================================
9
+
10
+ Scope
11
+ -----
12
+ This card summarizes the curated user/organization-related methods and how to call
13
+ them via the hf_api_request tool (no shell usage).
14
+
15
+ References:
16
+ - Curated method list (embedded below from scripts/hf_api_methods.txt)
17
+ - REST endpoints: scripts/hf_api_endpoints.txt
18
+ - Tool: hf_api_request (this card's function tool)
19
+
20
+ Prereqs
21
+ -------
22
+ - HF_TOKEN env var (or ~/.cache/huggingface/token)
23
+ - Optional: HF_ENDPOINT (default: https://huggingface.co)
24
+ - Optional: HF_MAX_RESULTS (default: 20)
25
+
26
+ Preferred: hf_api_request tool
27
+ ------------------------------
28
+ Tool call pattern:
29
+ - GET: hf_api_request(endpoint="/whoami-v2")
30
+ - GET with params: hf_api_request(endpoint="/users/{username}/likes")
31
+ - GET with local slicing: hf_api_request(endpoint="/users/{username}/likes", max_results=20, offset=20)
32
+ - POST: hf_api_request(endpoint="/.../comment", method="POST", json_body={...})
33
+
34
+ Notes:
35
+ - For repo operations, use /models, /datasets, or /spaces based on repo_type.
36
+ - Only GET/POST are supported by this tool. PATCH/DELETE are not supported.
37
+ - Mutation/update endpoints that require PATCH/DELETE (collection updates/deletes, unlike, etc.) are not supported.
38
+ - Avoid destructive operations unless the user explicitly confirms.
39
+ - List responses are client-sliced only; use max_results and offset to page
40
+ locally (the API still returns the full list).
41
+
42
+ USER DATA
43
+ ---------
44
+ - whoami
45
+ tool: hf_api_request(endpoint="/whoami-v2")
46
+
47
+ - activity (HTML scrape, not a public API endpoint)
48
+ tool: not available (HTML scrape is not supported by hf_api_request)
49
+
50
+ - get_user_overview
51
+ tool: hf_api_request(endpoint="/users/{username}/overview")
52
+
53
+ - list_liked_repos
54
+ tool: hf_api_request(endpoint="/users/{username}/likes")
55
+
56
+ - get_token_permission
57
+ tool: not available (use /whoami-v2 and check auth.accessToken.role)
58
+
59
+ USER NETWORK
60
+ ------------
61
+ - list_user_followers
62
+ tool: hf_api_request(endpoint="/users/{username}/followers")
63
+
64
+ - list_user_following
65
+ tool: hf_api_request(endpoint="/users/{username}/following")
66
+
67
+ ORGANIZATIONS
68
+ -------------
69
+ - get_organization_overview
70
+ tool: hf_api_request(endpoint="/organizations/{organization}/overview")
71
+
72
+ - list_organization_members
73
+ tool: hf_api_request(endpoint="/organizations/{organization}/members")
74
+
75
+ - list_organization_followers
76
+ tool: hf_api_request(endpoint="/organizations/{organization}/followers")
77
+
78
+ DISCUSSIONS & PULL REQUESTS
79
+ ---------------------------
80
+ - get_repo_discussions
81
+ tool: hf_api_request(
82
+ endpoint="/{repo_type}s/{repo_id}/discussions",
83
+ params={"type": "pr|discussion", "author": "<user>", "status": "open|closed"}
84
+ )
85
+
86
+ - get_discussion_details
87
+ tool: hf_api_request(
88
+ endpoint="/{repo_type}s/{repo_id}/discussions/{num}",
89
+ params={"diff": 1}
90
+ )
91
+
92
+ - create_discussion
93
+ tool: hf_api_request(
94
+ endpoint="/{repo_type}s/{repo_id}/discussions",
95
+ method="POST",
96
+ json_body={"title": "...", "description": "...", "pullRequest": false}
97
+ )
98
+
99
+ - create_pull_request
100
+ tool: hf_api_request(
101
+ endpoint="/{repo_type}s/{repo_id}/discussions",
102
+ method="POST",
103
+ json_body={"title": "...", "description": "...", "pullRequest": true}
104
+ )
105
+
106
+ - comment_discussion
107
+ tool: hf_api_request(
108
+ endpoint="/{repo_type}s/{repo_id}/discussions/{num}/comment",
109
+ method="POST",
110
+ json_body={"comment": "..."}
111
+ )
112
+
113
+ - edit_discussion_comment
114
+ tool: hf_api_request(
115
+ endpoint="/{repo_type}s/{repo_id}/discussions/{num}/comment/{comment_id}/edit",
116
+ method="POST",
117
+ json_body={"content": "..."}
118
+ )
119
+
120
+ - hide_discussion_comment (destructive)
121
+ tool: only with explicit confirmation:
122
+ hf_api_request(
123
+ endpoint="/{repo_type}s/{repo_id}/discussions/{num}/comment/{comment_id}/hide",
124
+ method="POST"
125
+ )
126
+
127
+ - change_discussion_status
128
+ tool: hf_api_request(
129
+ endpoint="/{repo_type}s/{repo_id}/discussions/{num}/status",
130
+ method="POST",
131
+ json_body={"status": "open|closed", "comment": "..."}
132
+ )
133
+
134
+ ACCESS REQUESTS (GATED REPOS)
135
+ -----------------------------
136
+ - list_pending_access_requests
137
+ tool: hf_api_request(endpoint="/{repo_type}s/{repo_id}/user-access-request/pending")
138
+
139
+ - list_accepted_access_requests
140
+ tool: hf_api_request(endpoint="/{repo_type}s/{repo_id}/user-access-request/accepted")
141
+
142
+ - list_rejected_access_requests
143
+ tool: hf_api_request(endpoint="/{repo_type}s/{repo_id}/user-access-request/rejected")
144
+
145
+ - accept_access_request
146
+ tool: hf_api_request(
147
+ endpoint="/{repo_type}s/{repo_id}/user-access-request/handle",
148
+ method="POST",
149
+ json_body={"user": "...", "status": "accepted"}
150
+ )
151
+
152
+ - cancel_access_request
153
+ tool: hf_api_request(
154
+ endpoint="/{repo_type}s/{repo_id}/user-access-request/handle",
155
+ method="POST",
156
+ json_body={"user": "...", "status": "pending"}
157
+ )
158
+
159
+ - reject_access_request (destructive)
160
+ tool: only with explicit confirmation:
161
+ hf_api_request(
162
+ endpoint="/{repo_type}s/{repo_id}/user-access-request/handle",
163
+ method="POST",
164
+ json_body={"user": "...", "status": "rejected", "rejectionReason": "..."}
165
+ )
166
+
167
+ - grant_access
168
+ tool: hf_api_request(
169
+ endpoint="/{repo_type}s/{repo_id}/user-access-request/grant",
170
+ method="POST",
171
+ json_body={"user": "..."}
172
+ )
173
+
174
+ USER COLLECTIONS
175
+ ----------------
176
+ - list_collections
177
+ tool: hf_api_request(endpoint="/collections", params={"owner": "<user-or-org>"})
178
+
179
+ - get_collection
180
+ tool: hf_api_request(endpoint="/collections/{slug}")
181
+
182
+ - create_collection
183
+ tool: hf_api_request(
184
+ endpoint="/collections",
185
+ method="POST",
186
+ json_body={"title": "...", "namespace": "<user-or-org>", "description": "...", "private": false}
187
+ )
188
+
189
+ - add_collection_item
190
+ tool: hf_api_request(
191
+ endpoint="/collections/{slug}/items",
192
+ method="POST",
193
+ json_body={"item": {"id": "...", "type": "model|dataset|space|paper"}, "note": "..."}
194
+ )
195
+
196
+ Note: Collection update/delete endpoints use PATCH/DELETE and are not supported by hf_api_request.
197
+
198
+ USER INTERACTIONS
199
+ -----------------
200
+ Note: Like/unlike endpoints are not available via hf_api_request.
201
+
202
+ - auth_check
203
+ tool: hf_api_request(endpoint="/{repo_type}s/{repo_id}/auth-check")
204
+
205
+ Direct REST usage example
206
+ -------------------------
207
+ hf_api_request(endpoint="/organizations/<org>/overview")
208
+
209
+ See scripts/hf_api_endpoints.txt for full endpoint details and expected request bodies.
210
+
211
+ Curated HfApi Methods: User & Organization Data, Discussions & Interactions
212
+ ===========================================================================
213
+ Note: PATCH/DELETE-only methods are excluded here; hf_api_request supports GET/POST only.
214
+
215
+ 28 methods selected from 126 total HfApi methods
216
+
217
+
218
+ USER DATA (4 methods)
219
+ ================================================================================
220
+
221
+ get_user_overview(username: str, token: ...) -> User
222
+ --------------------------------------------------------------------------------
223
+ Get an overview of a user on the Hub.
224
+
225
+ list_liked_repos(user: Optional[str] = None, *, token: ...) -> UserLikes
226
+ --------------------------------------------------------------------------------
227
+ List all public repos liked by a user on huggingface.co.
228
+
229
+ whoami(token: ...) -> Dict
230
+ --------------------------------------------------------------------------------
231
+ Call HF API to know "whoami".
232
+
233
+ get_token_permission(token: ...) -> Literal['read', 'write', 'fineGrained', None]
234
+ --------------------------------------------------------------------------------
235
+ Check if a given token is valid and return its permissions.
236
+
237
+
238
+ USER NETWORK (2 methods)
239
+ ================================================================================
240
+
241
+ list_user_followers(username: str, token: ...) -> Iterable[User]
242
+ --------------------------------------------------------------------------------
243
+ Get the list of followers of a user on the Hub.
244
+
245
+ list_user_following(username: str, token: ...) -> Iterable[User]
246
+ --------------------------------------------------------------------------------
247
+ Get the list of users followed by a user on the Hub.
248
+
249
+
250
+ ORGANIZATIONS (3 methods)
251
+ ================================================================================
252
+
253
+ get_organization_overview(organization: str, token: ...) -> Organization
254
+ --------------------------------------------------------------------------------
255
+ Get an overview of an organization on the Hub.
256
+
257
+ list_organization_members(organization: str, token: ...) -> Iterable[User]
258
+ --------------------------------------------------------------------------------
259
+ List of members of an organization on the Hub.
260
+
261
+ list_organization_followers(organization: str, token: ...) -> Iterable[User]
262
+ --------------------------------------------------------------------------------
263
+ List followers of an organization on the Hub.
264
+
265
+
266
+ DISCUSSIONS & PULL REQUESTS (8 methods)
267
+ ================================================================================
268
+
269
+ create_discussion(repo_id: str, title: str, *, token: ..., description: ..., repo_type: ..., pull_request: bool = False) -> DiscussionWithDetails
270
+ --------------------------------------------------------------------------------
271
+ Creates a Discussion or Pull Request.
272
+
273
+ create_pull_request(repo_id: str, title: str, *, token: ..., description: ..., repo_type: ...) -> DiscussionWithDetails
274
+ --------------------------------------------------------------------------------
275
+ Creates a Pull Request. Pull Requests created programmatically will be in "draft" status.
276
+
277
+ get_discussion_details(repo_id: str, discussion_num: int, *, repo_type: ..., token: ...) -> DiscussionWithDetails
278
+ --------------------------------------------------------------------------------
279
+ Fetches a Discussion's / Pull Request's details from the Hub.
280
+
281
+ get_repo_discussions(repo_id: str, *, author: ..., discussion_type: ..., discussion_status: ..., repo_type: ..., token: ...) -> Iterator[Discussion]
282
+ --------------------------------------------------------------------------------
283
+ Fetches Discussions and Pull Requests for the given repo.
284
+
285
+ comment_discussion(repo_id: str, discussion_num: int, comment: str, *, token: ..., repo_type: ...) -> DiscussionComment
286
+ --------------------------------------------------------------------------------
287
+ Creates a new comment on the given Discussion.
288
+
289
+ edit_discussion_comment(repo_id: str, discussion_num: int, comment_id: str, new_content: str, *, token: ..., repo_type: ...) -> DiscussionComment
290
+ --------------------------------------------------------------------------------
291
+ Edits a comment on a Discussion / Pull Request.
292
+
293
+ hide_discussion_comment(repo_id: str, discussion_num: int, comment_id: str, *, token: ..., repo_type: ...) -> DiscussionComment
294
+ --------------------------------------------------------------------------------
295
+ Hides a comment on a Discussion / Pull Request.
296
+
297
+ change_discussion_status(repo_id: str, discussion_num: int, status: str, *, token: ..., repo_type: ..., comment: ...) -> Discussion
298
+ --------------------------------------------------------------------------------
299
+ Changes the status of a Discussion or Pull Request.
300
+
301
+
302
+ ACCESS REQUESTS (GATED REPOS) (6 methods)
303
+ ================================================================================
304
+
305
+ list_pending_access_requests(repo_id: str, *, token: ..., repo_type: ...) -> List[AccessRequest]
306
+ --------------------------------------------------------------------------------
307
+ List pending access requests for a gated repo.
308
+
309
+ list_accepted_access_requests(repo_id: str, *, token: ..., repo_type: ...) -> List[AccessRequest]
310
+ --------------------------------------------------------------------------------
311
+ List accepted access requests for a gated repo.
312
+
313
+ list_rejected_access_requests(repo_id: str, *, token: ..., repo_type: ...) -> List[AccessRequest]
314
+ --------------------------------------------------------------------------------
315
+ List rejected access requests for a gated repo.
316
+
317
+ accept_access_request(repo_id: str, user: str, *, token: ..., repo_type: ...) -> None
318
+ --------------------------------------------------------------------------------
319
+ Accept access request to a gated repo.
320
+
321
+ reject_access_request(repo_id: str, user: str, *, token: ..., repo_type: ..., rejection_reason: ...) -> None
322
+ --------------------------------------------------------------------------------
323
+ Reject access request to a gated repo.
324
+
325
+ grant_access(repo_id: str, user: str, *, token: ..., repo_type: ...) -> None
326
+ --------------------------------------------------------------------------------
327
+ Grant access to a gated repo without an access request.
328
+
329
+
330
+ USER COLLECTIONS (4 methods)
331
+ ================================================================================
332
+
333
+ get_collection(collection_slug: str, *, token: ...) -> Collection
334
+ --------------------------------------------------------------------------------
335
+ Get a collection's details from the Hub.
336
+
337
+ create_collection(title: str, *, namespace: ..., description: ..., private: ..., token: ...) -> Collection
338
+ --------------------------------------------------------------------------------
339
+ Create a new collection on the Hub.
340
+
341
+ list_collections(*, owner: ..., item: ..., sort: ..., limit: ..., token: ...) -> Iterable[Collection]
342
+ --------------------------------------------------------------------------------
343
+ List collections on the Huggingface Hub, given some filters.
344
+
345
+ add_collection_item(collection_slug: str, item_id: str, item_type: CollectionItemType_T, *, note: ..., exists_ok: bool = False, token: ...) -> Collection
346
+ --------------------------------------------------------------------------------
347
+ Add an item to a collection on the Hub.
348
+
349
+
350
+ USER INTERACTIONS (1 method)
351
+ ================================================================================
352
+
353
+ auth_check(repo_id: str, *, repo_type: ..., token: ...) -> None
354
+ --------------------------------------------------------------------------------
355
+ Check if the provided user token has access to a specific repository on the Hugging Face Hub.