Sync local-intelligence eval harness
Browse files
eval/local_intelligence/grader.py
CHANGED
|
@@ -143,6 +143,25 @@ def _get(obj: Any, path: str, default: Any = None) -> Any:
|
|
| 143 |
return current
|
| 144 |
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
def _check(assertion: str, output: Any, test_input: dict[str, Any]) -> tuple[bool, str]:
|
| 147 |
if assertion.startswith('title is not "'):
|
| 148 |
banned = re.search(r'"([^"]+)"', assertion).group(1)
|
|
@@ -334,14 +353,14 @@ def _check(assertion: str, output: Any, test_input: dict[str, Any]) -> tuple[boo
|
|
| 334 |
if assertion == "item 2 depends on item 1":
|
| 335 |
items = _get(output, "items", _get(output, "checklist", []))
|
| 336 |
item = items[1] if isinstance(items, list) and len(items) > 1 else {}
|
| 337 |
-
deps = item.get("dependsOn", [])
|
| 338 |
-
return
|
| 339 |
|
| 340 |
if assertion == "item 3 depends on item 2 or item 1":
|
| 341 |
items = _get(output, "items", _get(output, "checklist", []))
|
| 342 |
item = items[2] if isinstance(items, list) and len(items) > 2 else {}
|
| 343 |
-
deps = item.get("dependsOn", [])
|
| 344 |
-
ok = any(dep in deps for dep in (
|
| 345 |
return ok, f"dependsOn={deps!r}"
|
| 346 |
|
| 347 |
if assertion == "only one node labeled Chris":
|
|
|
|
| 143 |
return current
|
| 144 |
|
| 145 |
|
| 146 |
+
def _normalize_dependency_refs(value: Any) -> list[str]:
|
| 147 |
+
if value is None:
|
| 148 |
+
return []
|
| 149 |
+
if isinstance(value, list):
|
| 150 |
+
refs: list[str] = []
|
| 151 |
+
for item in value:
|
| 152 |
+
refs.extend(_normalize_dependency_refs(item))
|
| 153 |
+
return refs
|
| 154 |
+
if isinstance(value, (int, float)):
|
| 155 |
+
return [str(int(value))]
|
| 156 |
+
if isinstance(value, str):
|
| 157 |
+
matches = re.findall(r"\d+", value)
|
| 158 |
+
if matches:
|
| 159 |
+
return matches
|
| 160 |
+
cleaned = value.strip()
|
| 161 |
+
return [cleaned] if cleaned else []
|
| 162 |
+
return []
|
| 163 |
+
|
| 164 |
+
|
| 165 |
def _check(assertion: str, output: Any, test_input: dict[str, Any]) -> tuple[bool, str]:
|
| 166 |
if assertion.startswith('title is not "'):
|
| 167 |
banned = re.search(r'"([^"]+)"', assertion).group(1)
|
|
|
|
| 353 |
if assertion == "item 2 depends on item 1":
|
| 354 |
items = _get(output, "items", _get(output, "checklist", []))
|
| 355 |
item = items[1] if isinstance(items, list) and len(items) > 1 else {}
|
| 356 |
+
deps = _normalize_dependency_refs(item.get("dependsOn", []))
|
| 357 |
+
return "1" in deps, f"dependsOn={deps!r}"
|
| 358 |
|
| 359 |
if assertion == "item 3 depends on item 2 or item 1":
|
| 360 |
items = _get(output, "items", _get(output, "checklist", []))
|
| 361 |
item = items[2] if isinstance(items, list) and len(items) > 2 else {}
|
| 362 |
+
deps = _normalize_dependency_refs(item.get("dependsOn", []))
|
| 363 |
+
ok = any(dep in deps for dep in ("1", "2"))
|
| 364 |
return ok, f"dependsOn={deps!r}"
|
| 365 |
|
| 366 |
if assertion == "only one node labeled Chris":
|