Merge pull request 'fix: trigger.operator null + 覆盖反馈重试 - Closes #22, Closes #21' (#25) from dev/issue-22-fix-trigger-null into main
CI / test (push) Successful in 7s
CI / test (push) Successful in 7s
This commit was merged in pull request #25.
This commit is contained in:
@@ -535,6 +535,20 @@ def _quick_validate(
|
|||||||
return passed, gaps
|
return passed, gaps
|
||||||
|
|
||||||
|
|
||||||
|
def _build_coverage_feedback(gaps: dict) -> str:
|
||||||
|
"""Generate feedback text for re-prompting when coverage is below threshold."""
|
||||||
|
lines = []
|
||||||
|
for item in gaps.get("missing_paths", []):
|
||||||
|
lines.append(f"- {item}")
|
||||||
|
if lines:
|
||||||
|
return (
|
||||||
|
"\n## 覆盖反馈(上一次运行未满足覆盖要求,请重新生成并修复以下缺口)\n\n"
|
||||||
|
+ "\n".join(lines)
|
||||||
|
+ "\n\n请重新审视文档,为缺失的章节和表格行创建对应的 function_unit。"
|
||||||
|
)
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def _collect_logic_tree_nodes(doc: dict) -> dict[str, dict[str, str]]:
|
def _collect_logic_tree_nodes(doc: dict) -> dict[str, dict[str, str]]:
|
||||||
"""Return {image_id: {node_id: node_type}} for all logic trees."""
|
"""Return {image_id: {node_id: node_type}} for all logic trees."""
|
||||||
result = {}
|
result = {}
|
||||||
@@ -750,6 +764,29 @@ def run_ensemble_semantic_index(doc: dict) -> dict:
|
|||||||
if v:
|
if v:
|
||||||
print(f" {k}: {len(v)} 个问题")
|
print(f" {k}: {len(v)} 个问题")
|
||||||
|
|
||||||
|
# Feedback retry: re-run with coverage feedback (one retry)
|
||||||
|
feedback = _build_coverage_feedback(gaps)
|
||||||
|
if feedback:
|
||||||
|
print(f"\n 覆盖反馈重试...")
|
||||||
|
try:
|
||||||
|
retry_prompt = build_prompt(doc, feedback, all_paths)
|
||||||
|
retry_result = call_llm(retry_prompt, max_retries=1, temperature=0.0)
|
||||||
|
n_retry_units = len(retry_result.get("function_units", []))
|
||||||
|
print(f" 重试返回: {n_retry_units} 功能单元")
|
||||||
|
if n_retry_units > 0:
|
||||||
|
# Merge retry into results and re-validate
|
||||||
|
semantic_indices.append(retry_result)
|
||||||
|
merged = ensemble_merge(semantic_indices)
|
||||||
|
merged["ensemble_temperatures"] = list(temperatures) + ["feedback_retry"]
|
||||||
|
passed, gaps = _quick_validate(merged, doc, all_paths)
|
||||||
|
merged["validation_passed"] = passed
|
||||||
|
merged["validation_gaps"] = {
|
||||||
|
k: v for k, v in gaps.items() if v
|
||||||
|
}
|
||||||
|
print(f" 重试后验证: {'PASS' if passed else 'GAPS FOUND'}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f" 覆盖反馈重试失败: {e}")
|
||||||
|
|
||||||
return merged
|
return merged
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -497,6 +497,13 @@ def main():
|
|||||||
print(f"\n[2/3] 逐单元提取 IR 规则...")
|
print(f"\n[2/3] 逐单元提取 IR 规则...")
|
||||||
fragments = extract_all_rules(semantic_index, doc)
|
fragments = extract_all_rules(semantic_index, doc)
|
||||||
|
|
||||||
|
# Filter out fragments with empty rules (LLM extraction failures)
|
||||||
|
empty_units = [f["unit_id"] for f in fragments
|
||||||
|
if not f.get("rules") and not f.get("error")]
|
||||||
|
if empty_units:
|
||||||
|
print(f" [WARN] {len(empty_units)} 个单元规则为空,已过滤: {empty_units}")
|
||||||
|
fragments = [f for f in fragments if f.get("rules") or f.get("error")]
|
||||||
|
|
||||||
# 3. Save
|
# 3. Save
|
||||||
print(f"\n[3/3] 保存 IR 片段...")
|
print(f"\n[3/3] 保存 IR 片段...")
|
||||||
config.save_json(fragments, config.IR_FRAGMENTS_JSON)
|
config.save_json(fragments, config.IR_FRAGMENTS_JSON)
|
||||||
|
|||||||
@@ -139,6 +139,10 @@ def _normalize_rule(rule: dict) -> dict:
|
|||||||
|
|
||||||
trigger = rule["trigger"]
|
trigger = rule["trigger"]
|
||||||
|
|
||||||
|
# Ensure trigger-level combining operator (AND/OR) for multi-condition triggers
|
||||||
|
if not trigger.get("operator"):
|
||||||
|
trigger["operator"] = "AND"
|
||||||
|
|
||||||
# If trigger has an event, it's event-based (no conditions needed)
|
# If trigger has an event, it's event-based (no conditions needed)
|
||||||
if trigger.get("event") is not None:
|
if trigger.get("event") is not None:
|
||||||
return rule
|
return rule
|
||||||
@@ -147,7 +151,7 @@ def _normalize_rule(rule: dict) -> dict:
|
|||||||
if "conditions" not in trigger:
|
if "conditions" not in trigger:
|
||||||
trigger["conditions"] = []
|
trigger["conditions"] = []
|
||||||
|
|
||||||
# Fix null operators in conditions
|
# Fix null operators in individual conditions
|
||||||
for cond in trigger["conditions"]:
|
for cond in trigger["conditions"]:
|
||||||
if not cond.get("operator"):
|
if not cond.get("operator"):
|
||||||
cond["operator"] = "=="
|
cond["operator"] = "=="
|
||||||
@@ -158,7 +162,6 @@ def _normalize_rule(rule: dict) -> dict:
|
|||||||
|
|
||||||
# If still no conditions, add a default one
|
# If still no conditions, add a default one
|
||||||
if not trigger["conditions"]:
|
if not trigger["conditions"]:
|
||||||
trigger["operator"] = "AND"
|
|
||||||
trigger["conditions"] = [{
|
trigger["conditions"] = [{
|
||||||
"signal": "system_state",
|
"signal": "system_state",
|
||||||
"operator": "==",
|
"operator": "==",
|
||||||
|
|||||||
Reference in New Issue
Block a user