feat(regulatory): 增加条件字段LLM复核

This commit is contained in:
2026-06-07 11:46:55 +08:00
parent a34684e490
commit 945669b9c2
4 changed files with 275 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ from pathlib import Path
from django.conf import settings
from review_agent.models import FileSummaryBatch
from review_agent.regulatory_review.services.llm_review import review_condition_fields
from review_agent.regulatory_review.services.text_extract import extract_text
@@ -20,10 +21,14 @@ def detect_regulatory_condition_candidates(summary_batch: FileSummaryBatch) -> d
corpus_parts = [summary_batch.product_name or ""]
field_candidates: dict[str, str] = {}
field_sources: dict[str, str] = {}
for item in summary_batch.items.order_by("file_index"):
corpus_parts.extend([item.directory_level, item.file_name, item.relative_path])
extracted = _extract_item_fields(item)
review = _extract_item_fields(item)
extracted = review.get("selected_fields", {})
sources = review.get("selected_sources", {})
field_candidates.update({key: value for key, value in extracted.items() if value and key not in field_candidates})
field_sources.update({key: value for key, value in sources.items() if value and key not in field_sources})
corpus_parts.extend(extracted.values())
corpus = "\n".join(part for part in corpus_parts if part)
product_name = field_candidates.get("产品名称") or _safe_summary_product_name(summary_batch.product_name)
@@ -51,21 +56,24 @@ def detect_regulatory_condition_candidates(summary_batch: FileSummaryBatch) -> d
"label": "产品名称",
"input_type": "text",
"suggested": product_name,
"source": field_sources.get("产品名称", "summary" if product_name else ""),
},
"model_spec": {
"label": "型号规格",
"input_type": "text",
"suggested": field_candidates.get("型号规格", ""),
"source": field_sources.get("型号规格", ""),
},
"intended_use": {
"label": "预期用途",
"input_type": "text",
"suggested": field_candidates.get("预期用途", ""),
"source": field_sources.get("预期用途", ""),
},
}
def _extract_item_fields(item) -> dict[str, str]:
def _extract_item_fields(item) -> dict[str, object]:
path = Path(item.storage_path)
if not path.is_absolute():
path = Path(settings.MEDIA_ROOT) / item.storage_path
@@ -74,7 +82,11 @@ def _extract_item_fields(item) -> dict[str, str]:
result = extract_text(path)
if result.status != "success" or not result.field_candidates:
return {}
return result.field_candidates
return review_condition_fields(
text=result.front_text or result.text,
rule_fields=result.field_candidates,
file_context=f"{item.directory_level}\n{item.file_name}\n{item.relative_path}",
)
def _safe_summary_product_name(product_name: str) -> str: