SPB Git

spb/ai-atlas

Public
6.5 KB · 93 lines python
1import pytest23from aiatlas.connectors.hub.huggingface import HuggingFaceConnector4from aiatlas.sdk.facts import Target5from tests.conftest import claims_of, entity_names, extract_from_fixture, fixture_path678@pytest.fixture9def connector() -> HuggingFaceConnector:10    return HuggingFaceConnector({"models_per_org": 20})111213async def test_discover_uses_registry_orgs(connector):14    targets = await connector.discover(None)  # type: ignore[arg-type]15    urls = {t.url for t in targets}16    assert "https://huggingface.co/papers" in urls17    assert "https://huggingface.co/models?author=Qwen&sort=downloads&p=0" in urls18    assert "https://huggingface.co/models?author=bartowski&sort=downloads&p=0" in urls19    assert len(targets) >= 40 and not any("/api/" in u for u in urls)202122async def test_listing(connector):23    target = Target(url="https://huggingface.co/models?author=Qwen&sort=downloads&p=0", doc_type="listing", key="listing:Qwen:0", meta={"hf_org": "Qwen", "page": 0})24    facts = await extract_from_fixture(connector, target, fixture_path("huggingface", "listing-qwen.html"))25    models = [e for e in facts.entities if e.entity_type == "model"]26    assert len(models) == 20                                   # models_per_org cap27    assert models[0].identifiers == {"hf_repo": "Qwen/Qwen3-0.6B"} and models[0].organization.name == "Qwen"28    c = claims_of(facts, "Qwen3-0.6B")29    assert c["metric.downloads"] == 20685071 and c["pipeline_tag"] == "text-generation" and c["openness"] == "open-weights"30    assert c["parameter_count"] == 75163238431    assert [t.url for t in facts.targets][:2] == ["https://huggingface.co/Qwen/Qwen3-0.6B", "https://huggingface.co/Qwen/Qwen3-VL-8B-Instruct"]32    assert all(t.doc_type == "model_page" for t in facts.targets)333435async def test_model_page(connector):36    target = Target(url="https://huggingface.co/Qwen/Qwen3-8B", doc_type="model_page", key="model:Qwen/Qwen3-8B", meta={"hf_repo": "Qwen/Qwen3-8B"})37    facts = await extract_from_fixture(connector, target, fixture_path("huggingface", "model-qwen3-8b.html"))38    c = claims_of(facts, "Qwen3-8B")39    assert c["license"] == "apache-2.0" and c["library_name"] == "transformers" and c["architecture"] == "Qwen3ForCausalLM"40    assert c["parameter_count"] == 8190735360 and c["release_date"] == "2025-04-27" and c["openness"] == "open-weights"41    assert c["metric.likes"] == 1366 and c["file_size_gb"] == 16.38 and c["base_model"] == ["Qwen/Qwen3-8B-Base"]42    rels = {(r.subject.name, r.predicate, r.object.name) for r in facts.relations}43    assert ("Qwen3-8B", "fine_tuned_from", "Qwen3-8B-Base") in rels and ("Qwen", "develops", "Qwen3-8B") in rels44    assert ("Qwen3-8B", "described_by", "arXiv:2505.09388") in rels45    assert [t.url for t in facts.targets] == ["https://huggingface.co/Qwen/Qwen3-8B/raw/main/README.md"]46    assert facts.document_entity is not None and facts.document_entity.identifiers == {"hf_repo": "Qwen/Qwen3-8B"}474849async def test_model_page_gguf_and_gated(connector):50    target = Target(url="https://huggingface.co/bartowski/Qwen3.8-27B-GGUF", doc_type="model_page", key="x", meta={"hf_repo": "bartowski/Qwen3.8-27B-GGUF"})51    facts = await extract_from_fixture(connector, target, fixture_path("huggingface", "model-bartowski-gguf.html"))52    c = claims_of(facts, "bartowski/Qwen3.8-27B-GGUF")                     # redistributor repos keep the full id as name53    assert c["quant_format"] == "gguf" and "Q4_K_M" in c["quantization"] and c["is_quantized"] is True and c["quantized_by"] == "bartowski"54    assert c["parameter_count"] == 27_000_000_000            # literally in the repo name55    assert facts.entities[0].name == "bartowski" and facts.entities[0].identifiers["registry_org"] == "bartowski"5657    target = Target(url="https://huggingface.co/meta-llama/Llama-3.1-8B-Instruct", doc_type="model_page", key="x", meta={"hf_repo": "meta-llama/Llama-3.1-8B-Instruct"})58    facts = await extract_from_fixture(connector, target, fixture_path("huggingface", "model-llama-gated.html"))59    c = claims_of(facts, "Llama-3.1-8B-Instruct")60    assert c["openness"] == "restricted" and c["gated"] == "manual" and c["license"] == "llama3.1"61    assert c["languages"] == ["en", "de", "fr", "it", "pt", "hi", "es", "th"]62    assert facts.targets == []                                 # gated card is not fetched (401 without auth)63    assert any(r.predicate == "fine_tuned_from" and r.attributes.get("base_model_relation") == "finetune" for r in facts.relations)646566async def test_model_card(connector):67    target = Target(url="https://huggingface.co/bartowski/Qwen3.8-27B-GGUF/raw/main/README.md", doc_type="model_card", key="x", meta={"hf_repo": "bartowski/Qwen3.8-27B-GGUF"})68    facts = await extract_from_fixture(connector, target, fixture_path("huggingface", "readme-bartowski-gguf.md"), content_type="text/markdown")69    assert claims_of(facts, "bartowski/Qwen3.8-27B-GGUF")["base_model"] == ["Qwen/Qwen3.8-27B"]70    assert ("bartowski/Qwen3.8-27B-GGUF", "quantized_from", "Qwen3.8-27B") in {(r.subject.name, r.predicate, r.object.name) for r in facts.relations}71    target = Target(url="https://huggingface.co/Qwen/Qwen3-8B/raw/main/README.md", doc_type="model_card", key="x", meta={"hf_repo": "Qwen/Qwen3-8B"})72    facts = await extract_from_fixture(connector, target, fixture_path("huggingface", "readme-qwen3-8b.md"), content_type="text/markdown")73    assert claims_of(facts, "Qwen3-8B")["license"] == "apache-2.0"74    assert not any(r.predicate in ("derived_from", "quantized_from") for r in facts.relations)   # typed relation comes from the page757677def test_derived_repo_naming():78    from aiatlas.connectors.hub.huggingface import _foreign_family7980    assert _foreign_family("NousResearch", "Meta-Llama-3.1-70B-Instruct") is True and _foreign_family("meta-llama", "Llama-3.1-70B-Instruct") is False81    assert _foreign_family("NousResearch", "Hermes-4-70B") is False and _foreign_family("Qwen", "Qwen3-8B") is False82    assert _foreign_family("mlx-community", "Kimi-K2.5") is True838485async def test_daily_papers(connector):86    facts = await extract_from_fixture(connector, Target(url="https://huggingface.co/papers", doc_type="listing", key="papers"), fixture_path("huggingface", "papers.html"))87    papers = [e for e in facts.entities if e.entity_type == "paper"]88    assert len(papers) == 25 and all("arxiv" in p.identifiers for p in papers)89    first = claims_of(facts, papers[0].name)90    assert first["arxiv_id"] == "2609.10715" and first["metric.upvotes"] == 157 and first["pdf_url"] == "https://arxiv.org/pdf/2609.10715"91    assert len(first["authors"]) > 10 and first["published_at"].startswith("2026-09-09")92    assert entity_names(facts, "paper")93
Files · c509d7e03d5aed8bc61fb24bc1c8bb3de1f4b9e2
Menu

Theme