feat(review): 审查结论改为结构化 JSON,移除二次 LLM 抽取
- checklist.py:系统提示加入结构化输出契约(只输出 {summary, issues[]},
引用 handle 必须真实存在、不得编造)
- review.py:review_frame 返回 {summary, issues, raw};仅在「不再请求工具」的回合
解析结论,中间工具回合的 content 永不解析;强制收口那次 chat 不传 tools
- report.py:删除 extract_issues 与 _EXTRACT_SYSTEM(不再需要第二次 LLM 调用);
新增 format_finding(用 .get,顺带修复缺 frame 键 KeyError);save_report 的
issues 省略时从 findings 拍平
- __main__.py:主流程改为 确定性检查 → review_frame → build_finding(合并+校验),
issues 由 flatten_issues 派生
顺带修复既有 gap:summarize 硬下标 KeyError、extract_issues 单行围栏解析失败。
This commit is contained in:
1 parent
f6d61f8d07
commit
f7fa8f14d9
8 files changed
+224
-140
No files matched your search
@@ -3,12 +3,16 @@
|
||||
流程:
|
||||
1. 用清单生成系统提示,喂入结构化证据 + 截图。
|
||||
2. LLM 若请求只读取证工具 → 执行后把观测回灌,再问(有界循环)。
|
||||
3. LLM 不再请求工具时,其输出即为该图框的审查结论。
|
||||
3. LLM 不再请求工具时,其输出(受约束的 JSON)即为该图框的审查结论。
|
||||
|
||||
结论是**结构化对象** `{"summary": str, "issues": [dict], "raw": str}`,
|
||||
不再依赖第二次 LLM 调用来抽取结构(见 `findings.parse_conclusion`)。
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
from ..cad_tools import READ_ONLY_TOOLS, is_write_tool
|
||||
from ..findings import parse_conclusion
|
||||
from ..llm_client import LlmClient, downsample_image_b64
|
||||
from ..mcp_client import McpError, McpToolError, result_images, result_texts
|
||||
|
||||
@@ -59,7 +63,7 @@ def _run_readonly_tool(ctx, name, args, image_budget):
|
||||
|
||||
|
||||
def review_frame(ctx, evidence, system_prompt, log=print):
|
||||
"""审查单个图框,返回审查意见文本。"""
|
||||
"""审查单个图框,返回结构化结论 `{"summary", "issues", "raw"}`。"""
|
||||
payload = evidence_payload(evidence)
|
||||
user_content = [
|
||||
{
|
||||
@@ -86,8 +90,9 @@ def review_frame(ctx, evidence, system_prompt, log=print):
|
||||
msg = resp.choices[0].message
|
||||
messages.append(msg)
|
||||
|
||||
# 仅在「不再请求工具」的回合解析结论;中间工具回合的 content 永不解析
|
||||
if not msg.tool_calls:
|
||||
return msg.content or ""
|
||||
return parse_conclusion(msg.content or "", log=log)
|
||||
|
||||
for tool_call in msg.tool_calls:
|
||||
name = tool_call.function.name
|
||||
@@ -101,12 +106,12 @@ def review_frame(ctx, evidence, system_prompt, log=print):
|
||||
{"role": "tool", "tool_call_id": tool_call.id, "content": content}
|
||||
)
|
||||
|
||||
# 达到回合上限:强制收口
|
||||
# 达到回合上限:强制收口(不传 tools,保证不再请求工具,输出必为终稿 JSON)
|
||||
messages.append(
|
||||
{
|
||||
"role": "user",
|
||||
"content": "已达到取证回合上限,请基于现有信息直接给出该图框的审查结论。",
|
||||
"content": "已达到取证回合上限,请基于现有信息直接给出该图框的审查结论(JSON)。",
|
||||
}
|
||||
)
|
||||
resp = ctx.llm.chat(messages)
|
||||
return resp.choices[0].message.content or ""
|
||||
return parse_conclusion(resp.choices[0].message.content or "", log=log)
|
||||
Reference in new issue
Block a user