MCPcopy
hub / github.com/IBM/AssetOpsBench / _load_scenario_dir

Function _load_scenario_dir

src/evaluation/loader.py:78–123  ·  view source on GitHub ↗

Load scenario folders from a directory containing groundtruth.txt files. Supports folder names like: scenario_34/ groundtruth.txt The scenario id becomes "34" so it can join with trajectory files such as: traces/trajectories/34.json

(path: Path)

Source from the content-addressed store, hash-verified

76
77
78def _load_scenario_dir(path: Path) -> list[Scenario]:
79 """Load scenario folders from a directory containing groundtruth.txt files.
80
81 Supports folder names like:
82 scenario_34/
83 groundtruth.txt
84
85 The scenario id becomes "34" so it can join with trajectory files such as:
86 traces/trajectories/34.json
87 """
88 scenarios: list[Scenario] = []
89
90 for child in sorted(path.iterdir()):
91 if not child.is_dir():
92 continue
93
94 groundtruth_path = child / "groundtruth.txt"
95 if not groundtruth_path.exists():
96 continue
97
98 scenario_id = child.name
99 if scenario_id.startswith("scenario_"):
100 scenario_id = scenario_id.removeprefix("scenario_")
101
102 expected_answer = groundtruth_path.read_text(encoding="utf-8").strip()
103
104 question_path = child / "question.txt"
105 text = (
106 question_path.read_text(encoding="utf-8").strip()
107 if question_path.exists()
108 else ""
109 )
110
111 scenarios.append(
112 Scenario.from_raw(
113 {
114 "id": scenario_id,
115 "text": text,
116 "type": "structured",
117 "expected_answer": expected_answer,
118 "scoring_method": "static_json",
119 }
120 )
121 )
122
123 return scenarios
124
125
126def _load_scenario_file(path: Path) -> list[Scenario]:

Callers 1

load_scenariosFunction · 0.85

Calls 1

from_rawMethod · 0.45

Tested by

no test coverage detected