Nhận PDF upload trực tiếp qua POST /parse

API trước đây chỉ nhận đường dẫn HDFS từ Airflow. Thêm endpoint
multipart/form-data nhận thẳng file PDF, vẫn chạy bất đồng bộ: trả 202 kèm
job_id và result_url, worker xử lý nền, client lấy dla-document-bundle ở
GET /jobs/{job_id}/result hoặc qua callback.

- File upload ghi xuống IDP_DATA_DIR/uploads theo sha256 nội dung nên gửi lại
  cùng request_id trả cùng job_id; file được xoá khi không còn job nào dùng.
- Thêm cột filename/source_kind để bundle giữ đúng tên file gốc thay vì tên
  đã băm.
- IDP_RUN_WORKER=1 chạy worker trong process API cho triển khai một host.
- IDP_OCR_BACKEND=pdf_text dựng bundle từ text layer của PDF để chạy thử toàn
  bộ luồng khi chưa serve được model.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-21 14:51:19 +00:00
parent 939e3bc8c1
commit c79ea9f05f
11 changed files with 343 additions and 31 deletions

View File

@@ -12,6 +12,8 @@ class Settings:
callback_hosts: str = os.getenv("IDP_CALLBACK_HOSTS", "")
ocr_url: str = os.getenv("IDP_OCR_URL", "http://localhost:9222/v1/chat/completions")
ocr_model: str = os.getenv("IDP_OCR_MODEL", "chandra")
ocr_backend: str = os.getenv("IDP_OCR_BACKEND", "http") # http hoặc pdf_text
run_worker: bool = os.getenv("IDP_RUN_WORKER", "0").lower() in ("1", "true", "yes")
ocr_workers: int = int(os.getenv("IDP_OCR_WORKERS", "64"))
max_queued_jobs: int = int(os.getenv("IDP_MAX_QUEUED_JOBS", "1000"))
max_pdf_bytes: int = int(os.getenv("IDP_MAX_PDF_BYTES", str(1024**3)))
@@ -25,6 +27,10 @@ class Settings:
lease_seconds: int = int(os.getenv("IDP_LEASE_SECONDS", "1800"))
poll_seconds: float = float(os.getenv("IDP_POLL_SECONDS", "0.5"))
@property
def upload_dir(self) -> Path:
return self.data_dir / "uploads"
@property
def db_path(self) -> Path:
return self.data_dir / "jobs.sqlite3"