zcbot/evaluation/inspect_bridge.py

48 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""将 zcbot JSON suite 导出为 Inspect AI 可摄取的 JSONL。
Inspect 运行环境与项目 `.venv` 隔离JSONL 是稳定交换契约。
"""
from __future__ import annotations
import json
from pathlib import Path
from .models import EvalSuite
def export_inspect_jsonl(suite: EvalSuite, output: Path) -> int:
output.parent.mkdir(parents=True, exist_ok=True)
lines: list[str] = []
for case in suite.cases:
record = {
"id": case.id,
"input": case.prompt,
# zcbot 使用结构化 assertions 评分,不强行伪造单一字符串 target。
"target": "",
"metadata": {
"name": case.name,
"dimension": case.dimension,
"weight": case.weight,
"repetitions": case.repetitions or suite.default_repetitions,
"timeout_s": case.timeout_s,
"skill": case.skill,
"model_profile": case.model_profile,
"tags": list(case.tags),
"assertions": [
{
"type": item.type,
"weight": item.weight,
"value": item.value,
"path": item.path,
"min_bytes": item.min_bytes,
"max_value": item.max_value,
"description": item.description,
}
for item in case.assertions
],
},
}
lines.append(json.dumps(record, ensure_ascii=False))
output.write_text("\n".join(lines) + "\n", encoding="utf-8")
return len(lines)