SPB Git forge

spb/ai-atlas

Public
41commits 1branches 0releases
4.6 MBsize
maindefault branch
12 days agolast push
HTML 77.2% TypeScript 10.5% Python 9.6% JavaScript 2.5%
4.4 KB · 54 lines python
Raw Blame History
1from collections import Counter23from aiatlas.connectors.providers.openrouter import OpenRouterConnector, _display_name, _per_mtok4from aiatlas.sdk.facts import Target5from tests.conftest import claims_of, extract_from_fixture, fixture_path678async def test_catalogue():9    c = OpenRouterConnector()10    target = Target(url="https://openrouter.ai/api/v1/models", doc_type="catalogue", key="models")11    facts = await extract_from_fixture(c, target, fixture_path("openrouter", "models.json"), content_type="application/json")12    models = [e for e in facts.entities if e.entity_type == "model"]13    assert len(models) >= 300 and not any(e.identifiers.get("openrouter", "").startswith("~") for e in models)     # alias rows skipped14    assert len(facts.prices) >= 15015    sonnet = next(p for p in facts.prices if p.provider_model_id == "anthropic/claude-sonnet-4.5")16    assert sonnet.model.name == "Claude Sonnet 4.5" and sonnet.model.organization.name == "Anthropic"17    # routed prices are OpenRouter's rows: booked on the aggregator only, the routed lab is a feature (never a second "current" price on its own provider)18    assert sonnet.provider.name == "OpenRouter" and sonnet.features["via"] == "openrouter" and sonnet.features["upstream_provider"] == "anthropic"19    assert sonnet.features["upstream_vendor"] == "anthropic"20    assert (sonnet.input_per_mtok, sonnet.output_per_mtok, sonnet.cached_input_per_mtok) == (3.0, 15.0, 0.3)   # per-token strings × 1e621    assert sonnet.model.identifiers == {"openrouter": "anthropic/claude-sonnet-4.5"} and "claude-sonnet-4.5" in sonnet.model.aliases22    assert "anthropic_model_id" not in sonnet.model.identifiers                                     # OpenRouter slugs ≠ vendor API ids23    assert sonnet.model.family is not None and sonnet.model.family.name == "Claude" and sonnet.model.identity_confidence == "medium"24    claims = claims_of(facts, "Claude Sonnet 4.5")25    assert claims["context_length"] == 1_000_000 and claims["max_output_tokens"] == 6400026    assert claims["openrouter_listed_at"] == "2025-09-29" and "release_date" not in claims           # listing date is not a release date27    assert claims["modalities_input"] == ["document", "image", "text"] and claims["file_input"] is True     # "file" → document (ontology)28    assert "tools" in claims["supported_parameters"] and claims["tool_calling"] is True29    by_provider = Counter(p.provider.name for p in facts.prices)30    assert set(by_provider) == {"OpenRouter"} and by_provider["OpenRouter"] >= 150                  # every routed price belongs to OpenRouter31    upstream = Counter(p.features.get("upstream_provider") for p in facts.prices)32    assert upstream["openai"] >= 50 and upstream[None] >= 50                                          # unknown vendors carry no upstream provider33    variant = next(p for p in facts.prices if ":" in (p.provider_model_id or ""))34    assert "variant" in variant.features and ":" not in variant.model.identifiers["openrouter"]      # variants share the model identity35    assert not any(p.input_per_mtok is not None and p.input_per_mtok < 0 for p in facts.prices)   # dynamic "-1" prices skipped36    assert any("hf_repo" in e.identifiers for e in models)37    assert not any(c.property == "release_date" for c in facts.claims)38    # OpenRouter's own routers are products, never models39    assert not any(e.identifiers.get("openrouter", "").startswith("openrouter/") for e in models)40    routers = [e for e in facts.entities if e.entity_type == "product"]41    assert {e.identifiers["openrouter"] for e in routers} >= {"openrouter/auto", "openrouter/pareto-code", "openrouter/free"}42    auto = next(e for e in routers if e.identifiers["openrouter"] == "openrouter/auto")43    assert auto.name == "Auto Router" and auto.attributes == {"kind": "router"} and auto.organization.name == "OpenRouter"44    assert any(r.predicate == "operates" and r.object is auto for r in facts.relations)45    assert not any(p.provider_model_id == "openrouter/auto" for p in facts.prices)              # dynamic (-1) price skipped46    free = next(p for p in facts.prices if p.provider_model_id == "openrouter/free")47    assert free.model.entity_type == "product" and free.input_per_mtok == 0.0484950def test_helpers():51    assert _display_name("Anthropic: Claude Sonnet 4.5", "anthropic") == "Claude Sonnet 4.5"52    assert _display_name("Sakana: Something", "sakana") == "Something"53    assert _per_mtok("0.000003") == 3.0 and _per_mtok("-1") == -1.0 and _per_mtok(None) is None54