Download testing/agent_evaluation/tests/support.py from yuhanqin/ut-evaluation: direct link, hf CLI and curl.
- Browser
- Download file 3.7 kB
-
https://huggingface.co/datasets/yuhanqin/ut-evaluation/resolve/main/testing/agent_evaluation/tests/support.py
- Command line
-
hf download hf://datasets/yuhanqin/ut-evaluation/testing/agent_evaluation/tests/support.py
-
curl -L -o support.py https://huggingface.co/datasets/yuhanqin/ut-evaluation/resolve/main/testing/agent_evaluation/tests/support.py
3.7 kB
| from __future__ import annotations | |
| import hashlib | |
| import json | |
| from dataclasses import dataclass | |
| from pathlib import Path | |
| from typing import Any, Callable, Mapping | |
| class CallableLLMBackend: | |
| """Test-only structured completion adapter.""" | |
| kind = "callable" | |
| provider = "callable" | |
| call: Callable[[str, Mapping[str, Any]], Mapping[str, Any]] | |
| model: str = "configured-api-model" | |
| name: str = "callable" | |
| def complete( | |
| self, | |
| prompt: str, | |
| *, | |
| output_schema: Mapping[str, Any], | |
| ) -> Mapping[str, Any]: | |
| return self.call(prompt, output_schema) | |
| def write_canonical_dataset( | |
| root: Path, | |
| cases: list[dict[str, Any]], | |
| *, | |
| metadata_schema: dict[str, Any] | None = None, | |
| dataset_id: str = "demo", | |
| dataset_version: str = "v1", | |
| ) -> Path: | |
| root.mkdir() | |
| schema = metadata_schema or {"type": "object"} | |
| raw = b"".join((json.dumps(case, ensure_ascii=False) + "\n").encode("utf-8") for case in cases) | |
| schema_bytes = (json.dumps(schema, ensure_ascii=False, sort_keys=True, separators=(",", ":")) + "\n").encode("utf-8") | |
| (root / "cases.jsonl").write_bytes(raw) | |
| (root / "manifest.json").write_text(json.dumps({ | |
| "schema_version": "dataset/v3", | |
| "dataset_id": dataset_id, | |
| "dataset_version": dataset_version, | |
| "case_count": len(cases), | |
| "case_ids": [case.get("case_id") for case in cases], | |
| "cases_file": "cases.jsonl", | |
| "cases_sha256": hashlib.sha256(raw).hexdigest(), | |
| "source_root": ".", | |
| "loader": "tests.support:load_cases", | |
| "dataset_config_sha256": "0" * 64, | |
| "metadata_schema_sha256": hashlib.sha256(schema_bytes).hexdigest(), | |
| "metadata_schema": schema, | |
| "builder_version": "test-builder-v1", | |
| }, ensure_ascii=False) + "\n", encoding="utf-8") | |
| return root | |
| def profile_text(evaluators: str, *, protocol: str = "eval-events/v1", event_carriers: str = "[llm_message, tool_call]", preserve_static: bool = False) -> str: | |
| # Keep test call sites concise while emitting the real v3 profile shape. | |
| # Individual tests can still override malformed instrumentation or unknown | |
| # evaluator IDs to exercise the parser/registry errors. | |
| import yaml | |
| parsed = yaml.safe_load("evaluators:\n" + evaluators) or {"evaluators": {}} | |
| for family, entries in parsed.get("evaluators", {}).items(): | |
| if not isinstance(entries, list): | |
| continue | |
| for entry in entries: | |
| if not isinstance(entry, dict): | |
| continue | |
| evaluator_id = entry.get("id", "") | |
| entry.setdefault("params", {}) | |
| # Profiles select an evaluator; static contract fields are owned | |
| # by the registry. Keep the helper's generated fixtures aligned | |
| # with the minimal v3 format. | |
| if not preserve_static: | |
| for key in ("family", "engine", "result_kind", "scope", "expansion", | |
| "aggregation", "direction", "version"): | |
| entry.pop(key, None) | |
| if isinstance(entry.get("llm"), dict): | |
| entry["llm"] = { | |
| key: value for key, value in entry["llm"].items() | |
| if key in {"backend", "model"} | |
| } | |
| body = yaml.safe_dump(parsed.get("evaluators", {}), sort_keys=False).splitlines() | |
| return ( | |
| "schema_version: skill-evaluation/v3\n" | |
| "evaluation:\n" | |
| " instrumentation:\n" | |
| f" protocol: {protocol}\n" | |
| f" event_carriers: {event_carriers}\n" | |
| " evaluators:\n" | |
| + "\n".join(" " + line for line in body) | |
| + "\n" | |
| ) | |