mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-26 12:12:10 +00:00
业务本体与标准实体:跨源键值对齐、对账共变算子、健康证据链与实体助手
- 新增标准业务实体(CanonicalEntity)模型、确定性跨源编码翻译、后台候选实体扫描与文档驱动实体智能助手 - 新增指标本体图谱(factor / reconciles_with / upstream_driver)、DAG 防环校验以及 ontology_neighbors / source_health 内置工具 - 新增跨源对账(analysis_reconcile)与滞后共变(analysis_cochange)分析算子,打通 [[h:H1]] 数据源健康证据链、报告导出与本体消融评测 - 数据目录新增「标准业务实体」视图与候选审阅工作台,口径页集成指标本体拓扑面板与端到端浏览器检查
This commit is contained in:
@@ -45,6 +45,9 @@ CATALOG_LABEL = {"live": "当前目录", "reviewed": "只用已核实和已确
|
||||
#: 分析工具开、关(变体的 analysis.tools)
|
||||
ANALYSIS_TOOLS = ("on", "off")
|
||||
ANALYSIS_TOOLS_LABEL = {"on": "开", "off": "关"}
|
||||
#: 本体穿透开、关(变体的 ontology.tools)
|
||||
ONTOLOGY_TOOLS = ("on", "off")
|
||||
ONTOLOGY_TOOLS_LABEL = {"on": "开", "off": "关"}
|
||||
REPEATS_MAX = 5
|
||||
#: 定时跑 1 次,A/B 对照缺省 3 次(评测-D10)
|
||||
SCHEDULE_REPEATS = 1
|
||||
@@ -52,7 +55,7 @@ PAIR_REPEATS = 3
|
||||
#: 一次 A/B 最多几臂(目录贡献对照最多三臂)
|
||||
ARMS_MAX = 3
|
||||
LABEL_MAX = 40
|
||||
_KEYS = ("assistant", "writer", "judge", "catalog", "analysis", "repeats", "label")
|
||||
_KEYS = ("assistant", "writer", "judge", "catalog", "analysis", "ontology", "repeats", "label")
|
||||
|
||||
|
||||
def _invalid(message: str, field_name: str) -> CaseInvalid:
|
||||
@@ -104,6 +107,10 @@ def normalize_variant(raw: Any, *, judge_default: bool = False, repeats_default:
|
||||
if not isinstance(analysis, Mapping) or set(analysis) - {"tools"} \
|
||||
or analysis.get("tools", "on") not in ANALYSIS_TOOLS:
|
||||
raise _invalid(f"变体的分析工具需要是 {{tools}},tools 只能是 {'、'.join(ANALYSIS_TOOLS)}(开、关)", "variant.analysis")
|
||||
ontology = {} if raw.get("ontology") is None else raw["ontology"]
|
||||
if not isinstance(ontology, Mapping) or set(ontology) - {"tools"} \
|
||||
or ontology.get("tools", "on") not in ONTOLOGY_TOOLS:
|
||||
raise _invalid(f"变体的本体穿透需要是 {{tools}},tools 只能是 {'、'.join(ONTOLOGY_TOOLS)}(开、关)", "variant.ontology")
|
||||
repeats = raw.get("repeats", repeats_default)
|
||||
if isinstance(repeats, bool) or not isinstance(repeats, int) or not 1 <= repeats <= REPEATS_MAX:
|
||||
raise _invalid(f"每题重复的次数需要是 1 到 {REPEATS_MAX} 的整数", "variant.repeats")
|
||||
@@ -113,7 +120,8 @@ def normalize_variant(raw: Any, *, judge_default: bool = False, repeats_default:
|
||||
return {"assistant": _model_pair(raw.get("assistant"), "助手模型", "variant.assistant"),
|
||||
"writer": _model_pair(raw.get("writer"), "写作模型", "variant.writer"),
|
||||
"judge": judge, "catalog": {"mode": catalog["mode"], "snapshot": snapshot},
|
||||
"analysis": {"tools": analysis.get("tools", "on")}, "repeats": repeats,
|
||||
"analysis": {"tools": analysis.get("tools", "on")},
|
||||
"ontology": {"tools": ontology.get("tools", "on")}, "repeats": repeats,
|
||||
"label": (label or "").strip()[:LABEL_MAX] or None}
|
||||
|
||||
|
||||
@@ -122,6 +130,11 @@ def analysis_tools(variant: Mapping[str, Any]) -> str:
|
||||
return "off" if (variant.get("analysis") or {}).get("tools") == "off" else "on"
|
||||
|
||||
|
||||
def ontology_tools(variant: Mapping[str, Any]) -> str:
|
||||
"""这一臂的本体穿透开不开:on / off。加这一项之前的变体(存着的老评测)没有它,按开。"""
|
||||
return "off" if (variant.get("ontology") or {}).get("tools") == "off" else "on"
|
||||
|
||||
|
||||
def catalog_preset(base: Mapping[str, Any], *, reviewed: bool = False) -> list[dict[str, Any]]:
|
||||
"""「目录的贡献」预设对照:当前目录 vs 关(reviewed 时再加「只用已核实和已确认的项」)。模型、裁判、重复次数照 base。"""
|
||||
arms = [("live", CATALOG_LABEL["live"]), ("off", CATALOG_LABEL["off"])]
|
||||
@@ -137,6 +150,12 @@ def analysis_tools_preset(base: Mapping[str, Any]) -> list[dict[str, Any]]:
|
||||
for tools in ANALYSIS_TOOLS]
|
||||
|
||||
|
||||
def ontology_tools_preset(base: Mapping[str, Any]) -> list[dict[str, Any]]:
|
||||
"""「本体穿透的贡献」预设对照:本体穿透开 vs 关。模型、目录、分析工具、裁判、重复次数照 base。"""
|
||||
return [{**copy.deepcopy(dict(base)), "ontology": {"tools": tools}, "label": f"本体穿透{ONTOLOGY_TOOLS_LABEL[tools]}"}
|
||||
for tools in ONTOLOGY_TOOLS]
|
||||
|
||||
|
||||
def arm_name(variant: Mapping[str, Any], index: int) -> str:
|
||||
"""这一臂的名字:变体里写了就用,否则按目录(只有目录不同时一看就懂),再不然 A、B、C。"""
|
||||
return str(variant.get("label") or "") or "ABC"[index]
|
||||
@@ -221,6 +240,8 @@ def variant_key(variant: Mapping[str, Any], models: Mapping[str, Any]) -> str:
|
||||
"snapshot": catalog.get("snapshot") if catalog.get("mode") == "snapshot" else None}
|
||||
if analysis_tools(variant) == "off":
|
||||
body["analysis_tools"] = "off"
|
||||
if ontology_tools(variant) == "off":
|
||||
body["ontology_tools"] = "off"
|
||||
return content_hash(canonical_json(body))[:16]
|
||||
|
||||
|
||||
@@ -231,12 +252,15 @@ def describe(variant: Mapping[str, Any], models: Mapping[str, Any] | None = None
|
||||
parts = [f"助手 {models.get('assistant') or (variant.get('assistant') or {}).get('model') or '缺省'}",
|
||||
f"写作 {models.get('writer') or (variant.get('writer') or {}).get('model') or '各节点自己的'}",
|
||||
CATALOG_LABEL.get(catalog.get("mode") or "live", "当前目录"),
|
||||
f"分析工具{ANALYSIS_TOOLS_LABEL[analysis_tools(variant)]}",
|
||||
f"结论裁判{'开' if variant.get('judge') else '关'}", f"每题 {variant.get('repeats') or 1} 次"]
|
||||
f"分析工具{ANALYSIS_TOOLS_LABEL[analysis_tools(variant)]}"]
|
||||
if ontology_tools(variant) == "off":
|
||||
parts.append(f"本体穿透{ONTOLOGY_TOOLS_LABEL['off']}")
|
||||
parts += [f"结论裁判{'开' if variant.get('judge') else '关'}", f"每题 {variant.get('repeats') or 1} 次"]
|
||||
return " · ".join(parts)
|
||||
|
||||
|
||||
__all__ = ["ANALYSIS_TOOLS", "ANALYSIS_TOOLS_LABEL", "ARMS_MAX", "CATALOG_LABEL", "CATALOG_MODES", "PAIR_REPEATS",
|
||||
__all__ = ["ANALYSIS_TOOLS", "ANALYSIS_TOOLS_LABEL", "ARMS_MAX", "CATALOG_LABEL", "CATALOG_MODES",
|
||||
"ONTOLOGY_TOOLS", "ONTOLOGY_TOOLS_LABEL", "PAIR_REPEATS",
|
||||
"REPEATS_MAX", "Resolved", "SCHEDULE_REPEATS", "VARIANT_INVALID", "VARIANT_UNAVAILABLE", "analysis_tools",
|
||||
"analysis_tools_preset", "arm_name", "catalog_preset", "describe", "normalize_variant", "resolve_models",
|
||||
"snapshot_artifact", "variant_key", "view_of"]
|
||||
"analysis_tools_preset", "arm_name", "catalog_preset", "describe", "normalize_variant", "ontology_tools",
|
||||
"ontology_tools_preset", "resolve_models", "snapshot_artifact", "variant_key", "view_of"]
|
||||
|
||||
Reference in New Issue
Block a user