KIE: bóc 2 lượt theo trang, mặc định Qwen3.5-4B

- Lượt 1: document_type, document_number, issued_date, issuing_authority,
  title chỉ trên 3 trang đầu.
- Lượt 2: signer chỉ trên trang DLA có Signature/Stamp; ưu tiên trang có
  Stamp trong thân trang (bỏ dấu giáp lai ở dải 10% mép), tối đa
  IDP_KIE_MAX_PAGES trang cuối; không có trang nào thì không gọi model.
- Viết lại description các trường theo yêu cầu nghiệp vụ.
- normalize_answer nhận signer trả về dạng mảng.
- IDP_KIE_URL/IDP_KIE_MODEL mặc định trỏ Qwen3.5-4B cổng 9224, không còn
  dùng chung model OCR (Chandra DLA sinh JSON lan man khi làm KIE).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-25 04:15:58 +00:00
parent 2039ddb487
commit 904134a224
5 changed files with 145 additions and 61 deletions

View File

@@ -92,7 +92,7 @@ class Worker:
self.settings.max_page_attempts)
def extract(self, job: dict):
"""Một lượt model bóc các trường cố định cho cả tài liệu, chạy sau khi mọi trang đã OCR xong."""
"""Bóc các trường cố định cho cả tài liệu, chạy sau khi mọi trang đã OCR xong để dùng block DLA."""
job_id, attempts = job["id"], job["extract_attempts"]
if not self.settings.kie_enabled or self.settings.ocr_backend == "pdf_text":
self.store.extract_done(job_id, attempts, None, status="skipped")
@@ -100,7 +100,10 @@ class Worker:
try:
if attempts > self.settings.max_kie_attempts:
raise ValueError("Extract lease expired too many times")
answer = extract_document(self.settings, self.job_dir(job_id) / "source.pdf", job["total_pages"])
page_blocks = {r["page_no"]: json.loads(r["result_json"])["blocks"]
for r in self.store.page_results(job_id) if r["status"] == "done"}
answer = extract_document(self.settings, self.job_dir(job_id) / "source.pdf",
job["total_pages"], page_blocks)
self.store.extract_done(job_id, attempts, json.dumps(answer, ensure_ascii=False))
log.info("Extracted fields for %s", job_id)
except Exception as exc: