Skip to content

Commit a8ba998

Browse files
committed
Expand HuggingFace author fallback to multiple known publishers
Support both Comfy-Org and Kijai author indexes as known HuggingFace fallbacks, aggregate their status in the backend, refresh the cached author index, and update the frontend UI and tests.
1 parent cb032c7 commit a8ba998

7 files changed

Lines changed: 7471 additions & 1671 deletions

File tree

__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,11 @@ def setup_routes(self):
494494
build_huggingface_custom_result,
495495
check_brave_search_api_key,
496496
check_huggingface_token,
497-
get_author_fallback_index_status,
498497
get_huggingface_download_url,
499498
get_huggingface_model_details,
499+
get_known_author_fallback_indexes_status,
500500
parse_huggingface_url,
501-
refresh_author_fallback_index,
501+
refresh_known_author_fallback_indexes,
502502
search_huggingface_for_file,
503503
)
504504
from .core.sources.huggingface import (
@@ -4535,7 +4535,9 @@ async def brave_api_key_check_route(request):
45354535
@json_api_endpoint("HuggingFace author index status")
45364536
async def huggingface_author_index_status_route(request):
45374537
"""Return local HuggingFace author fallback index status."""
4538-
return web.json_response(get_author_fallback_index_status())
4538+
return web.json_response(
4539+
get_known_author_fallback_indexes_status()
4540+
)
45394541

45404542
@routes.post("/model_resolver/huggingface/author-index/refresh")
45414543
@json_api_endpoint("HuggingFace author index refresh")
@@ -4544,7 +4546,7 @@ async def huggingface_author_index_refresh_route(request):
45444546
data = await request.json()
45454547
hf_token = data.get("hf_token", "")
45464548
result = await asyncio.to_thread(
4547-
refresh_author_fallback_index, hf_token or None
4549+
refresh_known_author_fallback_indexes, hf_token or None
45484550
)
45494551
clear_huggingface_search_cache()
45504552
return web.json_response(result)

core/sources/huggingface.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from .common import build_unified_search_result
3434

3535
HF_API_URL = "https://huggingface.co/api"
36-
HF_AUTHOR_FALLBACKS = ["Comfy-Org"]
36+
HF_AUTHOR_FALLBACKS = ["Comfy-Org", "Kijai"]
3737
BRAVE_SEARCH_API_URL = "https://api.search.brave.com/res/v1/web/search"
3838
HF_AUTHOR_INDEX_CACHE_TTL_SECONDS = 24 * 60 * 60
3939
HF_AUTHOR_INDEX_CACHE_VERSION = 1
@@ -284,6 +284,33 @@ def get_author_fallback_index_status(author: str = "Comfy-Org") -> Dict[str, Any
284284
}
285285

286286

287+
def get_known_author_fallback_indexes_status() -> Dict[str, Any]:
288+
"""Return aggregate status for all known HuggingFace author indexes."""
289+
author_statuses = [
290+
get_author_fallback_index_status(author) for author in HF_AUTHOR_FALLBACKS
291+
]
292+
updated_times = [
293+
status["updated_at"]
294+
for status in author_statuses
295+
if isinstance(status.get("updated_at"), (int, float))
296+
]
297+
cached_author_count = sum(bool(status["exists"]) for status in author_statuses)
298+
fully_cached = cached_author_count == len(author_statuses)
299+
300+
return {
301+
"authors": author_statuses,
302+
"author_count": len(author_statuses),
303+
"cached_author_count": cached_author_count,
304+
"exists": cached_author_count > 0,
305+
"fully_cached": fully_cached,
306+
"updated_at": max(updated_times) if updated_times else None,
307+
"stale": not fully_cached
308+
or any(bool(status["stale"]) for status in author_statuses),
309+
"repo_count": sum(int(status["repo_count"]) for status in author_statuses),
310+
"file_count": sum(int(status["file_count"]) for status in author_statuses),
311+
}
312+
313+
287314
def refresh_author_fallback_index(
288315
token: Optional[str] = None, author: str = "Comfy-Org"
289316
) -> Dict[str, Any]:
@@ -297,6 +324,25 @@ def refresh_author_fallback_index(
297324
return status
298325

299326

327+
def refresh_known_author_fallback_indexes(
328+
token: Optional[str] = None,
329+
) -> Dict[str, Any]:
330+
"""Force refresh all known public HuggingFace author indexes."""
331+
refresh_results = [
332+
refresh_author_fallback_index(token, author) for author in HF_AUTHOR_FALLBACKS
333+
]
334+
status = get_known_author_fallback_indexes_status()
335+
failed_authors = [
336+
result["author"] for result in refresh_results if not result.get("success")
337+
]
338+
status["success"] = not failed_authors
339+
status["persisted"] = all(
340+
bool(result.get("persisted")) for result in refresh_results
341+
)
342+
status["failed_authors"] = failed_authors
343+
return status
344+
345+
300346
def parse_huggingface_url(url: str) -> Optional[Dict[str, str]]:
301347
"""
302348
Parse a HuggingFace URL to extract repo and filename.

0 commit comments

Comments
 (0)