feat(shipping-notice): 增强订单抽取功能,添加进度事件和诊断运行管理,优化数据模型和访问控制
This commit is contained in:
1 parent
ce26d6d0c4
commit
c4095b08da
175 files changed
+13064
-1814
No files matched your search
@@ -16,6 +16,7 @@ from typing import Any
|
||||
|
||||
from app.models import ShippingNoticeDocument
|
||||
from app.services.shipping_notice.notice_lines import normalize_notice_line, parse_notice_table_text
|
||||
from app.services.shipping_notice.order_schema.table_contract import compile_table_header_contract
|
||||
|
||||
ADJUDICATION_SCHEMA_VERSION = "shipping-field-adjudication-v1"
|
||||
ADJUDICATED_LINE_FIELDS = (
|
||||
@@ -127,11 +128,14 @@ def _make_observation(
|
||||
return {"observation_id": _observation_id(payload), **payload}
|
||||
|
||||
|
||||
def _backend_rows(documents: list[ShippingNoticeDocument]) -> list[dict[str, Any]]:
|
||||
def _backend_rows(
|
||||
documents: list[ShippingNoticeDocument], *, schema_definition: dict[str, Any],
|
||||
) -> list[dict[str, Any]]:
|
||||
"""从每个锁定 Document 的保留列边界文本生成后端表格 Observation 原料。"""
|
||||
contract = compile_table_header_contract(schema_definition)
|
||||
rows: list[dict[str, Any]] = []
|
||||
for document in documents:
|
||||
for row in parse_notice_table_text(str(document.extracted_text or "")):
|
||||
for row in parse_notice_table_text(str(document.extracted_text or ""), contract=contract):
|
||||
if isinstance(row, dict):
|
||||
rows.append({**row, "_document_id": int(document.id)})
|
||||
return rows
|
||||
@@ -323,6 +327,7 @@ def adjudicate_order_fields(
|
||||
*,
|
||||
raw_order: dict[str, Any],
|
||||
documents: list[ShippingNoticeDocument],
|
||||
schema_definition: dict[str, Any],
|
||||
field_confidence: dict[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
@@ -334,12 +339,13 @@ def adjudicate_order_fields(
|
||||
summary: 已去除抽取元数据的 Dify 业务摘要。
|
||||
raw_order: Dify 原始订单对象,保留 evidence 与原始复合值。
|
||||
documents: 当前 Intake 的锁定 Document 集合。
|
||||
schema_definition: 与本次输入一同冻结的完整订单 Schema 定义。
|
||||
field_confidence: Dify 自报字段置信度,仅作弱权重。
|
||||
Returns:
|
||||
包含 canonical summary、不可变 observations、decisions 和 conflicts 的裁决结果。
|
||||
"""
|
||||
raw_lines = summary.get("lines") if isinstance(summary.get("lines"), list) else []
|
||||
backend_rows = _backend_rows(documents)
|
||||
backend_rows = _backend_rows(documents, schema_definition=schema_definition)
|
||||
documents_by_id = {int(item.id): item for item in documents}
|
||||
evidence_items = [item for item in (raw_order.get("evidence") or []) if isinstance(item, dict)]
|
||||
confidence = dict(field_confidence or {})
|
||||
|
||||
Reference in new issue
Block a user