feat(ai): add tenant-safe hierarchical expense learning
This commit is contained in:
@@ -210,6 +210,48 @@ def pre_review_public_payload(flag: dict[str, Any] | None) -> dict[str, Any] | N
|
||||
for item in list(flag.get("findings") or [])
|
||||
if isinstance(item, dict)
|
||||
],
|
||||
"historical_case_evidence": _public_historical_evidence(flag),
|
||||
}
|
||||
|
||||
|
||||
def _public_historical_evidence(flag: dict[str, Any]) -> list[dict[str, Any]]:
|
||||
result: list[dict[str, Any]] = []
|
||||
for item in list(flag.get("historical_case_evidence") or []):
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
public_item = _historical_evidence_public_payload(item)
|
||||
if public_item is not None:
|
||||
result.append(public_item)
|
||||
return result
|
||||
|
||||
|
||||
def _historical_evidence_public_payload(
|
||||
item: dict[str, Any],
|
||||
) -> dict[str, Any] | None:
|
||||
label = _text(item.get("label")).lower()
|
||||
if label not in {"confirmed", "false_positive"}:
|
||||
return None
|
||||
return {
|
||||
"label": label,
|
||||
"label_text": (
|
||||
"历史已确认,仅供复核"
|
||||
if label == "confirmed"
|
||||
else "历史误报,仅供复核"
|
||||
),
|
||||
"advisory_only": True,
|
||||
"score": round(float(item.get("score") or 0.0), 4),
|
||||
"scene_code": _text(item.get("scene_code")),
|
||||
"policy_ref": _text(item.get("policy_ref")),
|
||||
"rule_version": _text(item.get("rule_version")),
|
||||
"version_status": (
|
||||
"stale" if bool(item.get("stale")) else "matched"
|
||||
),
|
||||
"stale": bool(item.get("stale")),
|
||||
"summary": (
|
||||
"历史相似案例经人工复核确认风险成立。"
|
||||
if label == "confirmed"
|
||||
else "历史相似案例经人工复核判定为误报。"
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user