Spaces:
Paused
Paused
File size: 794 Bytes
0b84707 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import json
from pathlib import Path
from src.models import EvalSample
def load_dataset(path: str | Path) -> list[EvalSample]:
path = Path(path)
if not path.exists():
raise FileNotFoundError(f"Dataset not found: {path}")
raw = json.loads(path.read_text(encoding="utf-8"))
if isinstance(raw, list):
items = raw
elif isinstance(raw, dict) and "samples" in raw:
items = raw["samples"]
else:
raise ValueError("Dataset must be a list or dict with 'samples' key")
samples = []
for i, item in enumerate(items):
sample = EvalSample(
id=str(item.get("id", i + 1)),
prompt=item["prompt"],
expected_answer=item["expected_answer"],
)
samples.append(sample)
return samples
|