- 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>
52 lines
2.6 KiB
Python
52 lines
2.6 KiB
Python
import os
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Settings:
|
|
data_dir: Path = Path(os.getenv("IDP_DATA_DIR", "./data")).resolve()
|
|
storage: str = os.getenv("IDP_STORAGE", "local") # local, hdfs, or hdfs_cli
|
|
hdfs_url: str = os.getenv("IDP_HDFS_URL", "http://namenode:9870")
|
|
hdfs_native_uri: str = os.getenv("IDP_HDFS_NATIVE_URI", "")
|
|
api_key: str = os.getenv("IDP_API_KEY", "")
|
|
callback_hosts: str = os.getenv("IDP_CALLBACK_HOSTS", "")
|
|
callback_basic_user: str = os.getenv("IDP_CALLBACK_BASIC_USER", "")
|
|
callback_basic_password: str = os.getenv("IDP_CALLBACK_BASIC_PASSWORD", "")
|
|
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
|
|
kie_enabled: bool = os.getenv("IDP_KIE_ENABLED", "1").lower() in ("1", "true", "yes")
|
|
kie_url: str = os.getenv("IDP_KIE_URL", "http://localhost:9224/v1/chat/completions")
|
|
kie_model: str = os.getenv("IDP_KIE_MODEL", "qwen3.5-4b")
|
|
kie_max_pages: int = int(os.getenv("IDP_KIE_MAX_PAGES", "5"))
|
|
kie_timeout: int = int(os.getenv("IDP_KIE_TIMEOUT", "300"))
|
|
kie_max_tokens: int = int(os.getenv("IDP_KIE_MAX_TOKENS", "2048"))
|
|
max_kie_attempts: int = int(os.getenv("IDP_MAX_KIE_ATTEMPTS", "3"))
|
|
run_worker: bool = os.getenv("IDP_RUN_WORKER", "0").lower() in ("1", "true", "yes")
|
|
ocr_workers: int = int(os.getenv("IDP_OCR_WORKERS", "64"))
|
|
callback_workers: int = int(os.getenv("IDP_CALLBACK_WORKERS", "4"))
|
|
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)))
|
|
max_pages: int = int(os.getenv("IDP_MAX_PAGES", "5000"))
|
|
max_page_attempts: int = int(os.getenv("IDP_MAX_PAGE_ATTEMPTS", "3"))
|
|
max_job_attempts: int = int(os.getenv("IDP_MAX_JOB_ATTEMPTS", "3"))
|
|
max_callback_attempts: int = int(os.getenv("IDP_MAX_CALLBACK_ATTEMPTS", "10"))
|
|
voffice_decrypt_mode: str = os.getenv("IDP_VOFFICE_DECRYPT_MODE", "auto").lower()
|
|
voffice_des_key_hex: str = os.getenv("IDP_VOFFICE_DES_KEY_HEX", "a1e3c21919adeeab")
|
|
ocr_timeout: int = int(os.getenv("IDP_OCR_TIMEOUT", "180"))
|
|
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"
|
|
|
|
@property
|
|
def work_dir(self) -> Path:
|
|
return self.data_dir / "work"
|