Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- packages/eval-entity-resolver/src/eval_entity_resolver/strategies/__pycache__/fuzzy.cpython-314.pyc +0 -0
- src/eval_card_registry/__pycache__/cli.cpython-314.pyc +0 -0
- src/eval_card_registry/__pycache__/main.cpython-314.pyc +0 -0
- src/eval_card_registry/api/__pycache__/deps.cpython-314.pyc +0 -0
- src/eval_card_registry/api/__pycache__/routes_aliases.cpython-314.pyc +0 -0
- src/eval_card_registry/api/__pycache__/routes_entities.cpython-314.pyc +0 -0
- src/eval_card_registry/api/__pycache__/routes_health.cpython-314.pyc +0 -0
- src/eval_card_registry/api/__pycache__/routes_orgs.cpython-314.pyc +0 -0
- src/eval_card_registry/api/__pycache__/schemas.cpython-314.pyc +0 -0
- src/eval_card_registry/api/deps.py +11 -0
- src/eval_card_registry/api/routes_aliases.py +1 -7
- src/eval_card_registry/api/routes_entities.py +1 -7
- src/eval_card_registry/api/routes_health.py +10 -6
- src/eval_card_registry/api/routes_orgs.py +71 -0
- src/eval_card_registry/cli.py +2 -2
- src/eval_card_registry/main.py +2 -2
- src/eval_card_registry/services/__pycache__/resolution_service.cpython-314.pyc +0 -0
- src/eval_card_registry/services/resolution_service.py +47 -35
- src/eval_card_registry/store/__pycache__/hf_store.cpython-314.pyc +0 -0
- src/eval_card_registry/store/__pycache__/queries.cpython-314.pyc +0 -0
- src/eval_card_registry/store/__pycache__/schemas.cpython-314.pyc +0 -0
- src/eval_card_registry/store/hf_store.py +3 -3
- src/eval_card_registry/store/queries.py +3 -4
- uv-3e9b937509f5d126.lock +0 -0
packages/eval-entity-resolver/src/eval_entity_resolver/strategies/__pycache__/fuzzy.cpython-314.pyc
CHANGED
|
Binary files a/packages/eval-entity-resolver/src/eval_entity_resolver/strategies/__pycache__/fuzzy.cpython-314.pyc and b/packages/eval-entity-resolver/src/eval_entity_resolver/strategies/__pycache__/fuzzy.cpython-314.pyc differ
|
|
|
src/eval_card_registry/__pycache__/cli.cpython-314.pyc
CHANGED
|
Binary files a/src/eval_card_registry/__pycache__/cli.cpython-314.pyc and b/src/eval_card_registry/__pycache__/cli.cpython-314.pyc differ
|
|
|
src/eval_card_registry/__pycache__/main.cpython-314.pyc
CHANGED
|
Binary files a/src/eval_card_registry/__pycache__/main.cpython-314.pyc and b/src/eval_card_registry/__pycache__/main.cpython-314.pyc differ
|
|
|
src/eval_card_registry/api/__pycache__/deps.cpython-314.pyc
ADDED
|
Binary file (642 Bytes). View file
|
|
|
src/eval_card_registry/api/__pycache__/routes_aliases.cpython-314.pyc
CHANGED
|
Binary files a/src/eval_card_registry/api/__pycache__/routes_aliases.cpython-314.pyc and b/src/eval_card_registry/api/__pycache__/routes_aliases.cpython-314.pyc differ
|
|
|
src/eval_card_registry/api/__pycache__/routes_entities.cpython-314.pyc
CHANGED
|
Binary files a/src/eval_card_registry/api/__pycache__/routes_entities.cpython-314.pyc and b/src/eval_card_registry/api/__pycache__/routes_entities.cpython-314.pyc differ
|
|
|
src/eval_card_registry/api/__pycache__/routes_health.cpython-314.pyc
CHANGED
|
Binary files a/src/eval_card_registry/api/__pycache__/routes_health.cpython-314.pyc and b/src/eval_card_registry/api/__pycache__/routes_health.cpython-314.pyc differ
|
|
|
src/eval_card_registry/api/__pycache__/routes_orgs.cpython-314.pyc
ADDED
|
Binary file (5.1 kB). View file
|
|
|
src/eval_card_registry/api/__pycache__/schemas.cpython-314.pyc
CHANGED
|
Binary files a/src/eval_card_registry/api/__pycache__/schemas.cpython-314.pyc and b/src/eval_card_registry/api/__pycache__/schemas.cpython-314.pyc differ
|
|
|
src/eval_card_registry/api/deps.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import Depends, HTTPException
|
| 2 |
+
|
| 3 |
+
from eval_card_registry.config import settings
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def check_writable():
|
| 7 |
+
if settings.read_only:
|
| 8 |
+
raise HTTPException(status_code=405, detail="Write operations disabled in read-only mode")
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
writable = [Depends(check_writable)]
|
src/eval_card_registry/api/routes_aliases.py
CHANGED
|
@@ -3,19 +3,13 @@ from typing import Optional
|
|
| 3 |
|
| 4 |
from fastapi import APIRouter, Depends, HTTPException
|
| 5 |
|
|
|
|
| 6 |
from eval_card_registry.api.schemas import AliasPatch, AliasStatus, EntityType
|
| 7 |
-
from eval_card_registry.config import settings
|
| 8 |
from eval_card_registry.store.hf_store import get_store, RegistryStore
|
| 9 |
from eval_card_registry.store import queries
|
| 10 |
|
| 11 |
|
| 12 |
-
def _check_writable():
|
| 13 |
-
if settings.read_only:
|
| 14 |
-
raise HTTPException(status_code=405, detail="Write operations disabled in read-only mode")
|
| 15 |
-
|
| 16 |
-
|
| 17 |
router = APIRouter()
|
| 18 |
-
_writable = [Depends(_check_writable)]
|
| 19 |
|
| 20 |
|
| 21 |
@router.get("/aliases")
|
|
|
|
| 3 |
|
| 4 |
from fastapi import APIRouter, Depends, HTTPException
|
| 5 |
|
| 6 |
+
from eval_card_registry.api.deps import writable as _writable
|
| 7 |
from eval_card_registry.api.schemas import AliasPatch, AliasStatus, EntityType
|
|
|
|
| 8 |
from eval_card_registry.store.hf_store import get_store, RegistryStore
|
| 9 |
from eval_card_registry.store import queries
|
| 10 |
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
router = APIRouter()
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
@router.get("/aliases")
|
src/eval_card_registry/api/routes_entities.py
CHANGED
|
@@ -3,6 +3,7 @@ from typing import Optional
|
|
| 3 |
|
| 4 |
from fastapi import APIRouter, Depends, HTTPException
|
| 5 |
|
|
|
|
| 6 |
from eval_card_registry.api.schemas import (
|
| 7 |
BenchmarkCreate, BenchmarkPatch,
|
| 8 |
HarnessCreate, HarnessPatch,
|
|
@@ -10,17 +11,10 @@ from eval_card_registry.api.schemas import (
|
|
| 10 |
ModelCreate, ModelPatch,
|
| 11 |
ReviewStatus,
|
| 12 |
)
|
| 13 |
-
from eval_card_registry.config import settings
|
| 14 |
from eval_card_registry.store.hf_store import get_store, RegistryStore
|
| 15 |
from eval_card_registry.store import queries
|
| 16 |
|
| 17 |
-
|
| 18 |
-
def _check_writable():
|
| 19 |
-
if settings.read_only:
|
| 20 |
-
raise HTTPException(status_code=405, detail="Write operations disabled in read-only mode")
|
| 21 |
-
|
| 22 |
router = APIRouter()
|
| 23 |
-
_writable = [Depends(_check_writable)]
|
| 24 |
|
| 25 |
|
| 26 |
def _get_or_404(store, table, entity_id):
|
|
|
|
| 3 |
|
| 4 |
from fastapi import APIRouter, Depends, HTTPException
|
| 5 |
|
| 6 |
+
from eval_card_registry.api.deps import writable as _writable
|
| 7 |
from eval_card_registry.api.schemas import (
|
| 8 |
BenchmarkCreate, BenchmarkPatch,
|
| 9 |
HarnessCreate, HarnessPatch,
|
|
|
|
| 11 |
ModelCreate, ModelPatch,
|
| 12 |
ReviewStatus,
|
| 13 |
)
|
|
|
|
| 14 |
from eval_card_registry.store.hf_store import get_store, RegistryStore
|
| 15 |
from eval_card_registry.store import queries
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
router = APIRouter()
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
def _get_or_404(store, table, entity_id):
|
src/eval_card_registry/api/routes_health.py
CHANGED
|
@@ -5,16 +5,20 @@ from eval_card_registry.store.hf_store import get_store, RegistryStore
|
|
| 5 |
router = APIRouter()
|
| 6 |
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
@router.get("/health")
|
| 9 |
def health(store: RegistryStore = Depends(get_store)):
|
| 10 |
return {
|
| 11 |
"status": "ok",
|
| 12 |
"store": "loaded" if store.loaded else "not_loaded",
|
| 13 |
"entities": {
|
| 14 |
-
"models":
|
| 15 |
-
"benchmarks":
|
| 16 |
-
"metrics":
|
| 17 |
-
"harnesses":
|
| 18 |
},
|
| 19 |
}
|
| 20 |
|
|
@@ -42,6 +46,6 @@ def stats(store: RegistryStore = Depends(get_store)):
|
|
| 42 |
"metrics": _counts("canonical_metrics"),
|
| 43 |
"harnesses": _counts("eval_harnesses"),
|
| 44 |
"aliases": aliases_stats,
|
| 45 |
-
"resolution_log": {"total":
|
| 46 |
-
"sync_runs": {"total":
|
| 47 |
}
|
|
|
|
| 5 |
router = APIRouter()
|
| 6 |
|
| 7 |
|
| 8 |
+
def _safe_count(store: RegistryStore, table: str) -> int:
|
| 9 |
+
return len(store.table(table)) if store.has_table(table) else 0
|
| 10 |
+
|
| 11 |
+
|
| 12 |
@router.get("/health")
|
| 13 |
def health(store: RegistryStore = Depends(get_store)):
|
| 14 |
return {
|
| 15 |
"status": "ok",
|
| 16 |
"store": "loaded" if store.loaded else "not_loaded",
|
| 17 |
"entities": {
|
| 18 |
+
"models": _safe_count(store, "canonical_models"),
|
| 19 |
+
"benchmarks": _safe_count(store, "canonical_benchmarks"),
|
| 20 |
+
"metrics": _safe_count(store, "canonical_metrics"),
|
| 21 |
+
"harnesses": _safe_count(store, "eval_harnesses"),
|
| 22 |
},
|
| 23 |
}
|
| 24 |
|
|
|
|
| 46 |
"metrics": _counts("canonical_metrics"),
|
| 47 |
"harnesses": _counts("eval_harnesses"),
|
| 48 |
"aliases": aliases_stats,
|
| 49 |
+
"resolution_log": {"total": _safe_count(store, "resolution_log")},
|
| 50 |
+
"sync_runs": {"total": _safe_count(store, "sync_runs")},
|
| 51 |
}
|
src/eval_card_registry/api/routes_orgs.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from typing import Optional
|
| 3 |
+
|
| 4 |
+
from fastapi import APIRouter, Depends, HTTPException
|
| 5 |
+
|
| 6 |
+
from eval_card_registry.api.deps import writable as _writable
|
| 7 |
+
from eval_card_registry.api.schemas import OrgCreate, OrgPatch, ReviewStatus
|
| 8 |
+
from eval_card_registry.store.hf_store import get_store, RegistryStore
|
| 9 |
+
from eval_card_registry.store import queries
|
| 10 |
+
|
| 11 |
+
router = APIRouter()
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def _get_or_404(store, entity_id):
|
| 15 |
+
entity = queries.get_entity(store, "canonical_orgs", entity_id)
|
| 16 |
+
if entity is None:
|
| 17 |
+
raise HTTPException(status_code=404, detail=f"canonical_orgs '{entity_id}' not found")
|
| 18 |
+
return entity
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
_JSON_FIELDS = {"tags", "metadata"}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _encode(data: dict) -> dict:
|
| 25 |
+
out = {}
|
| 26 |
+
for k, v in data.items():
|
| 27 |
+
if k in _JSON_FIELDS and isinstance(v, (list, dict)):
|
| 28 |
+
out[k] = json.dumps(v)
|
| 29 |
+
else:
|
| 30 |
+
out[k] = v
|
| 31 |
+
return out
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def _decode(entity: dict) -> dict:
|
| 35 |
+
out = {}
|
| 36 |
+
for k, v in entity.items():
|
| 37 |
+
if k in _JSON_FIELDS and isinstance(v, str):
|
| 38 |
+
try:
|
| 39 |
+
out[k] = json.loads(v)
|
| 40 |
+
except (json.JSONDecodeError, TypeError):
|
| 41 |
+
out[k] = v
|
| 42 |
+
else:
|
| 43 |
+
out[k] = v
|
| 44 |
+
return out
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
@router.get("/orgs")
|
| 48 |
+
def list_orgs(
|
| 49 |
+
search: Optional[str] = None,
|
| 50 |
+
review_status: Optional[ReviewStatus] = None,
|
| 51 |
+
store: RegistryStore = Depends(get_store),
|
| 52 |
+
):
|
| 53 |
+
return [_decode(e) for e in queries.list_entities(store, "canonical_orgs", search=search, review_status=review_status)]
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
@router.get("/orgs/{org_id}")
|
| 57 |
+
def get_org(org_id: str, store: RegistryStore = Depends(get_store)):
|
| 58 |
+
return _decode(_get_or_404(store, org_id))
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
@router.post("/orgs", status_code=201, dependencies=_writable)
|
| 62 |
+
def create_org(body: OrgCreate, store: RegistryStore = Depends(get_store)):
|
| 63 |
+
return _decode(queries.upsert_entity(store, "canonical_orgs", _encode(body.model_dump())))
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
@router.patch("/orgs/{org_id}", dependencies=_writable)
|
| 67 |
+
def patch_org(org_id: str, body: OrgPatch, store: RegistryStore = Depends(get_store)):
|
| 68 |
+
_get_or_404(store, org_id)
|
| 69 |
+
data = {k: v for k, v in body.model_dump().items() if v is not None}
|
| 70 |
+
data["id"] = org_id
|
| 71 |
+
return _decode(queries.upsert_entity(store, "canonical_orgs", _encode(data)))
|
src/eval_card_registry/cli.py
CHANGED
|
@@ -14,6 +14,7 @@ import yaml
|
|
| 14 |
|
| 15 |
from eval_card_registry.store.hf_store import get_store
|
| 16 |
from eval_card_registry.store import queries
|
|
|
|
| 17 |
|
| 18 |
app = typer.Typer(help="eval-card-registry CLI")
|
| 19 |
|
|
@@ -124,8 +125,7 @@ def seed(
|
|
| 124 |
for idx in seed_aliases.index:
|
| 125 |
row = seed_aliases.loc[idx]
|
| 126 |
sc = row.get("source_config")
|
| 127 |
-
|
| 128 |
-
if sc is None or (isinstance(sc, float) and sc != sc) or (hasattr(sc, "__class__") and sc.__class__.__name__ == "NAType"):
|
| 129 |
sc = None
|
| 130 |
key = (row["raw_value"], row["entity_type"], row["canonical_id"], sc)
|
| 131 |
if key in yaml_alias_keys:
|
|
|
|
| 14 |
|
| 15 |
from eval_card_registry.store.hf_store import get_store
|
| 16 |
from eval_card_registry.store import queries
|
| 17 |
+
from eval_card_registry.store.queries import _is_na
|
| 18 |
|
| 19 |
app = typer.Typer(help="eval-card-registry CLI")
|
| 20 |
|
|
|
|
| 125 |
for idx in seed_aliases.index:
|
| 126 |
row = seed_aliases.loc[idx]
|
| 127 |
sc = row.get("source_config")
|
| 128 |
+
if _is_na(sc):
|
|
|
|
| 129 |
sc = None
|
| 130 |
key = (row["raw_value"], row["entity_type"], row["canonical_id"], sc)
|
| 131 |
if key in yaml_alias_keys:
|
src/eval_card_registry/main.py
CHANGED
|
@@ -3,7 +3,7 @@ from contextlib import asynccontextmanager
|
|
| 3 |
from fastapi import FastAPI
|
| 4 |
|
| 5 |
from eval_card_registry.config import settings
|
| 6 |
-
from eval_card_registry.store.hf_store import get_store,
|
| 7 |
from eval_card_registry.services.resolution_service import ResolutionService
|
| 8 |
from eval_card_registry.services.log_writer import ResolveLogWriter
|
| 9 |
from eval_card_registry.api.routes_resolve import router as resolve_router
|
|
@@ -16,7 +16,7 @@ from eval_card_registry.api.routes_health import router as health_router
|
|
| 16 |
async def lifespan(app: FastAPI):
|
| 17 |
store = get_store()
|
| 18 |
if settings.read_only:
|
| 19 |
-
store.load(tables=
|
| 20 |
else:
|
| 21 |
store.load()
|
| 22 |
|
|
|
|
| 3 |
from fastapi import FastAPI
|
| 4 |
|
| 5 |
from eval_card_registry.config import settings
|
| 6 |
+
from eval_card_registry.store.hf_store import get_store, QUERY_TABLE_NAMES
|
| 7 |
from eval_card_registry.services.resolution_service import ResolutionService
|
| 8 |
from eval_card_registry.services.log_writer import ResolveLogWriter
|
| 9 |
from eval_card_registry.api.routes_resolve import router as resolve_router
|
|
|
|
| 16 |
async def lifespan(app: FastAPI):
|
| 17 |
store = get_store()
|
| 18 |
if settings.read_only:
|
| 19 |
+
store.load(tables=QUERY_TABLE_NAMES)
|
| 20 |
else:
|
| 21 |
store.load()
|
| 22 |
|
src/eval_card_registry/services/__pycache__/resolution_service.cpython-314.pyc
CHANGED
|
Binary files a/src/eval_card_registry/services/__pycache__/resolution_service.cpython-314.pyc and b/src/eval_card_registry/services/__pycache__/resolution_service.cpython-314.pyc differ
|
|
|
src/eval_card_registry/services/resolution_service.py
CHANGED
|
@@ -55,6 +55,32 @@ def _build_alias_store(registry_store: RegistryStore) -> AliasStore:
|
|
| 55 |
return AliasStore(aliases_df, read_only=True)
|
| 56 |
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
class ResolutionService:
|
| 59 |
def __init__(self, registry_store: RegistryStore) -> None:
|
| 60 |
self.store = registry_store
|
|
@@ -89,13 +115,7 @@ class ResolutionService:
|
|
| 89 |
- canonical_id, strategy, confidence, created_new, review_status
|
| 90 |
"""
|
| 91 |
if not raw_value or not raw_value.strip():
|
| 92 |
-
return
|
| 93 |
-
"canonical_id": None,
|
| 94 |
-
"strategy": "no_match",
|
| 95 |
-
"confidence": 0.0,
|
| 96 |
-
"created_new": False,
|
| 97 |
-
"review_status": None,
|
| 98 |
-
}
|
| 99 |
|
| 100 |
# Fast path: return cached result for duplicate (raw_value, entity_type, source_config)
|
| 101 |
cache_key = (raw_value, entity_type, source_config)
|
|
@@ -108,21 +128,14 @@ class ResolutionService:
|
|
| 108 |
result: ResolutionResult = resolver.resolve(raw_value, entity_type, source_config)
|
| 109 |
if result.canonical_id is not None:
|
| 110 |
entity = queries.get_entity(self.store, _ENTITY_TABLE[entity_type], result.canonical_id)
|
| 111 |
-
result_dict =
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
"
|
| 116 |
-
|
| 117 |
-
}
|
| 118 |
else:
|
| 119 |
-
result_dict =
|
| 120 |
-
"canonical_id": None,
|
| 121 |
-
"strategy": "no_match",
|
| 122 |
-
"confidence": 0.0,
|
| 123 |
-
"created_new": False,
|
| 124 |
-
"review_status": None,
|
| 125 |
-
}
|
| 126 |
self._resolve_cache[cache_key] = result_dict
|
| 127 |
return result_dict
|
| 128 |
|
|
@@ -131,13 +144,12 @@ class ResolutionService:
|
|
| 131 |
existing = queries.get_alias(self.store, raw_value, entity_type, source_config)
|
| 132 |
if existing:
|
| 133 |
entity = queries.get_entity(self.store, _ENTITY_TABLE[entity_type], existing["canonical_id"])
|
| 134 |
-
result_dict =
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
"
|
| 139 |
-
|
| 140 |
-
}
|
| 141 |
self._resolve_cache[cache_key] = result_dict
|
| 142 |
return result_dict
|
| 143 |
|
|
@@ -218,13 +230,13 @@ class ResolutionService:
|
|
| 218 |
self.invalidate_resolver()
|
| 219 |
|
| 220 |
entity = queries.get_entity(self.store, _ENTITY_TABLE[entity_type], canonical_id)
|
| 221 |
-
result_dict =
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
"
|
| 226 |
-
|
| 227 |
-
|
| 228 |
self._resolve_cache[cache_key] = result_dict
|
| 229 |
return result_dict
|
| 230 |
|
|
|
|
| 55 |
return AliasStore(aliases_df, read_only=True)
|
| 56 |
|
| 57 |
|
| 58 |
+
def _no_match_result() -> dict:
|
| 59 |
+
return {
|
| 60 |
+
"canonical_id": None,
|
| 61 |
+
"strategy": "no_match",
|
| 62 |
+
"confidence": 0.0,
|
| 63 |
+
"created_new": False,
|
| 64 |
+
"review_status": None,
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _match_result(
|
| 69 |
+
canonical_id: str,
|
| 70 |
+
strategy: str,
|
| 71 |
+
confidence: float,
|
| 72 |
+
review_status: Optional[str],
|
| 73 |
+
created_new: bool = False,
|
| 74 |
+
) -> dict:
|
| 75 |
+
return {
|
| 76 |
+
"canonical_id": canonical_id,
|
| 77 |
+
"strategy": strategy,
|
| 78 |
+
"confidence": confidence,
|
| 79 |
+
"created_new": created_new,
|
| 80 |
+
"review_status": review_status,
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
|
| 84 |
class ResolutionService:
|
| 85 |
def __init__(self, registry_store: RegistryStore) -> None:
|
| 86 |
self.store = registry_store
|
|
|
|
| 115 |
- canonical_id, strategy, confidence, created_new, review_status
|
| 116 |
"""
|
| 117 |
if not raw_value or not raw_value.strip():
|
| 118 |
+
return _no_match_result()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
# Fast path: return cached result for duplicate (raw_value, entity_type, source_config)
|
| 121 |
cache_key = (raw_value, entity_type, source_config)
|
|
|
|
| 128 |
result: ResolutionResult = resolver.resolve(raw_value, entity_type, source_config)
|
| 129 |
if result.canonical_id is not None:
|
| 130 |
entity = queries.get_entity(self.store, _ENTITY_TABLE[entity_type], result.canonical_id)
|
| 131 |
+
result_dict = _match_result(
|
| 132 |
+
result.canonical_id,
|
| 133 |
+
result.strategy,
|
| 134 |
+
result.confidence,
|
| 135 |
+
entity.get("review_status") if entity else None,
|
| 136 |
+
)
|
|
|
|
| 137 |
else:
|
| 138 |
+
result_dict = _no_match_result()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
self._resolve_cache[cache_key] = result_dict
|
| 140 |
return result_dict
|
| 141 |
|
|
|
|
| 144 |
existing = queries.get_alias(self.store, raw_value, entity_type, source_config)
|
| 145 |
if existing:
|
| 146 |
entity = queries.get_entity(self.store, _ENTITY_TABLE[entity_type], existing["canonical_id"])
|
| 147 |
+
result_dict = _match_result(
|
| 148 |
+
existing["canonical_id"],
|
| 149 |
+
existing["strategy"],
|
| 150 |
+
existing["confidence"],
|
| 151 |
+
entity.get("review_status") if entity else None,
|
| 152 |
+
)
|
|
|
|
| 153 |
self._resolve_cache[cache_key] = result_dict
|
| 154 |
return result_dict
|
| 155 |
|
|
|
|
| 230 |
self.invalidate_resolver()
|
| 231 |
|
| 232 |
entity = queries.get_entity(self.store, _ENTITY_TABLE[entity_type], canonical_id)
|
| 233 |
+
result_dict = _match_result(
|
| 234 |
+
canonical_id,
|
| 235 |
+
strategy_used,
|
| 236 |
+
result.confidence,
|
| 237 |
+
entity.get("review_status") if entity else "draft",
|
| 238 |
+
created_new=created_new,
|
| 239 |
+
)
|
| 240 |
self._resolve_cache[cache_key] = result_dict
|
| 241 |
return result_dict
|
| 242 |
|
src/eval_card_registry/store/__pycache__/hf_store.cpython-314.pyc
CHANGED
|
Binary files a/src/eval_card_registry/store/__pycache__/hf_store.cpython-314.pyc and b/src/eval_card_registry/store/__pycache__/hf_store.cpython-314.pyc differ
|
|
|
src/eval_card_registry/store/__pycache__/queries.cpython-314.pyc
CHANGED
|
Binary files a/src/eval_card_registry/store/__pycache__/queries.cpython-314.pyc and b/src/eval_card_registry/store/__pycache__/queries.cpython-314.pyc differ
|
|
|
src/eval_card_registry/store/__pycache__/schemas.cpython-314.pyc
CHANGED
|
Binary files a/src/eval_card_registry/store/__pycache__/schemas.cpython-314.pyc and b/src/eval_card_registry/store/__pycache__/schemas.cpython-314.pyc differ
|
|
|
src/eval_card_registry/store/hf_store.py
CHANGED
|
@@ -27,7 +27,7 @@ def _fixtures_path() -> Path:
|
|
| 27 |
return Path(os.environ.get("FIXTURES_PATH", settings.fixtures_path))
|
| 28 |
|
| 29 |
|
| 30 |
-
|
| 31 |
"canonical_models",
|
| 32 |
"canonical_benchmarks",
|
| 33 |
"canonical_metrics",
|
|
@@ -39,7 +39,7 @@ _TABLE_NAMES = [
|
|
| 39 |
]
|
| 40 |
|
| 41 |
# Tables needed for query-only (read-only) mode
|
| 42 |
-
|
| 43 |
"canonical_models",
|
| 44 |
"canonical_benchmarks",
|
| 45 |
"canonical_metrics",
|
|
@@ -65,7 +65,7 @@ class RegistryStore:
|
|
| 65 |
Args:
|
| 66 |
tables: Specific table names to load. If None, loads all tables.
|
| 67 |
"""
|
| 68 |
-
names = tables or
|
| 69 |
if _local_mode():
|
| 70 |
self._load_from_fixtures(_fixtures_path(), names)
|
| 71 |
else:
|
|
|
|
| 27 |
return Path(os.environ.get("FIXTURES_PATH", settings.fixtures_path))
|
| 28 |
|
| 29 |
|
| 30 |
+
TABLE_NAMES = [
|
| 31 |
"canonical_models",
|
| 32 |
"canonical_benchmarks",
|
| 33 |
"canonical_metrics",
|
|
|
|
| 39 |
]
|
| 40 |
|
| 41 |
# Tables needed for query-only (read-only) mode
|
| 42 |
+
QUERY_TABLE_NAMES = [
|
| 43 |
"canonical_models",
|
| 44 |
"canonical_benchmarks",
|
| 45 |
"canonical_metrics",
|
|
|
|
| 65 |
Args:
|
| 66 |
tables: Specific table names to load. If None, loads all tables.
|
| 67 |
"""
|
| 68 |
+
names = tables or TABLE_NAMES
|
| 69 |
if _local_mode():
|
| 70 |
self._load_from_fixtures(_fixtures_path(), names)
|
| 71 |
else:
|
src/eval_card_registry/store/queries.py
CHANGED
|
@@ -40,10 +40,9 @@ def _row_to_dict(row: pd.Series) -> dict:
|
|
| 40 |
|
| 41 |
def _records(df: pd.DataFrame) -> list[dict]:
|
| 42 |
"""Convert a DataFrame to list-of-dicts, coercing NA/NaN to None for JSON."""
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
]
|
| 47 |
|
| 48 |
|
| 49 |
# ------------------------------------------------------------------
|
|
|
|
| 40 |
|
| 41 |
def _records(df: pd.DataFrame) -> list[dict]:
|
| 42 |
"""Convert a DataFrame to list-of-dicts, coercing NA/NaN to None for JSON."""
|
| 43 |
+
if df.empty:
|
| 44 |
+
return []
|
| 45 |
+
return df.astype(object).mask(df.isna(), None).to_dict(orient="records")
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
# ------------------------------------------------------------------
|
uv-3e9b937509f5d126.lock
ADDED
|
File without changes
|