Load scenarios from one or more files or directories. Supported inputs: 1. Existing JSON / JSONL scenario files. 2. A directory containing scenario subdirectories, each with ``groundtruth.txt``. For example: scenarios_data/ scenario_11/ groundtruth.txt scenario_1
(paths: Iterable[Path] | Path)
| 43 | |
| 44 | |
| 45 | def load_scenarios(paths: Iterable[Path] | Path) -> list[Scenario]: |
| 46 | """Load scenarios from one or more files or directories. |
| 47 | |
| 48 | Supported inputs: |
| 49 | |
| 50 | 1. Existing JSON / JSONL scenario files. |
| 51 | 2. A directory containing scenario subdirectories, each with |
| 52 | ``groundtruth.txt``. For example: |
| 53 | |
| 54 | scenarios_data/ |
| 55 | scenario_11/ |
| 56 | groundtruth.txt |
| 57 | scenario_12/ |
| 58 | groundtruth.txt |
| 59 | |
| 60 | For folder-based scenarios, the folder name becomes the scenario id and |
| 61 | ``groundtruth.txt`` becomes ``expected_answer``. |
| 62 | """ |
| 63 | if isinstance(paths, (str, Path)): |
| 64 | paths = [Path(paths)] |
| 65 | |
| 66 | out: list[Scenario] = [] |
| 67 | for p in paths: |
| 68 | p = Path(p) |
| 69 | |
| 70 | if p.is_dir(): |
| 71 | out.extend(_load_scenario_dir(p)) |
| 72 | else: |
| 73 | out.extend(_load_scenario_file(p)) |
| 74 | |
| 75 | return out |
| 76 | |
| 77 | |
| 78 | def _load_scenario_dir(path: Path) -> list[Scenario]: |