From b679c02e3a076b8e1dac02cca8b8fecaa3beb7a1 Mon Sep 17 00:00:00 2001 From: Peter Zhang <18501667167@qq.com> Date: Sun, 31 May 2026 22:08:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=B9=E8=BF=9B=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E5=8F=8D=E9=A6=88=E9=87=8D=E8=AF=95=20=E2=80=94=20=E6=9B=B4?= =?UTF-8?q?=E5=85=B7=E4=BD=93=E7=9A=84=E6=8F=90=E7=A4=BA=20+=20=E8=AF=8A?= =?UTF-8?q?=E6=96=AD=E6=97=A5=E5=BF=97=20-=20Closes=20#21?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 反馈文本增加 5 条明确的修复动作指令 - 重试使用 T=0.3(而非 0.0)获得更多样输出 - 添加重试 prompt 长度、新增 sections 等诊断日志 - 重试失败时打印完整 traceback Co-Authored-By: Claude Opus 4.7 --- .../step1_semantic_index.py | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/skills/ir_generation_skill/step1_semantic_index.py b/skills/ir_generation_skill/step1_semantic_index.py index 650e0b5..f0e35e0 100644 --- a/skills/ir_generation_skill/step1_semantic_index.py +++ b/skills/ir_generation_skill/step1_semantic_index.py @@ -536,17 +536,24 @@ def _quick_validate( def _build_coverage_feedback(gaps: dict) -> str: - """Generate feedback text for re-prompting when coverage is below threshold.""" - lines = [] + """Generate targeted feedback text for re-prompting when coverage is below threshold.""" + parts = [] 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 "" + parts.append(f"- {item}") + if not parts: + return "" + + return ( + "\n## 关键覆盖反馈(上一轮 LLM 输出了以下缺口,请重新处理)\n\n" + + "\n".join(parts) + + "\n\n" + "### 修复动作(必须执行)\n\n" + "1. **重新扫描上述每个缺失章节**,从文字和表格中提取所有可被测试的功能行为\n" + "2. **为每个缺失的表格行创建独立的 function_unit**,不得合并不同行的规则\n" + "3. **每个 function_unit 必须引用具体的 section 号和 row 号**作为 source\n" + "4. **非功能章节可以跳过**(如背景、术语、变更日志),但行为规则章节必须覆盖\n" + "5. 输出中必须包含针对上述缺口的新 function_unit\n" + ) def _collect_logic_tree_nodes(doc: dict) -> dict[str, dict[str, str]]: @@ -767,13 +774,22 @@ def run_ensemble_semantic_index(doc: dict) -> dict: # Feedback retry: re-run with coverage feedback (one retry) feedback = _build_coverage_feedback(gaps) if feedback: - print(f"\n 覆盖反馈重试...") + print(f"\n 覆盖反馈重试 (feedback长度={len(feedback)}字符)...", flush=True) try: retry_prompt = build_prompt(doc, feedback, all_paths) - retry_result = call_llm(retry_prompt, max_retries=1, temperature=0.0) + print(f" 重试 prompt 长度: {len(retry_prompt)} 字符", flush=True) + retry_result = call_llm(retry_prompt, max_retries=1, temperature=0.3) n_retry_units = len(retry_result.get("function_units", [])) - print(f" 重试返回: {n_retry_units} 功能单元") + n_retry_concepts = len(retry_result.get("concepts", [])) + print(f" 重试返回: {n_retry_concepts} 概念, {n_retry_units} 功能单元", flush=True) if n_retry_units > 0: + # Check which new sections were covered + retry_sections = set() + for fu in retry_result.get("function_units", []): + for src in fu.get("sources", []): + if src.get("section"): + retry_sections.add(src["section"]) + print(f" 重试新增 sections: {sorted(retry_sections)}", flush=True) # Merge retry into results and re-validate semantic_indices.append(retry_result) merged = ensemble_merge(semantic_indices) @@ -783,9 +799,11 @@ def run_ensemble_semantic_index(doc: dict) -> dict: merged["validation_gaps"] = { k: v for k, v in gaps.items() if v } - print(f" 重试后验证: {'PASS' if passed else 'GAPS FOUND'}") + print(f" 重试后验证: {'PASS' if passed else 'GAPS FOUND'}", flush=True) except Exception as e: - print(f" 覆盖反馈重试失败: {e}") + print(f" 覆盖反馈重试失败: {e}", flush=True) + import traceback + traceback.print_exc() return merged