refactor: Use bytes as options key (#58)

Signed-off-by: Eugene <fogaprod@gmail.com>
This commit is contained in:
Eugene
2025-02-21 21:03:27 +04:00
committed by GitHub
parent 36967f7f61
commit d5557fad9f

View File

@@ -265,7 +265,7 @@ ConvertDocumentsRequest = Union[
# Document converters will be preloaded and stored in a dictionary
converters: Dict[str, DocumentConverter] = {}
converters: Dict[bytes, DocumentConverter] = {}
# Custom serializer for PdfFormatOption
@@ -301,7 +301,7 @@ def _serialize_pdf_format_option(pdf_format_option: PdfFormatOption) -> str:
# Computes the PDF pipeline options and returns the PdfFormatOption and its hash
def get_pdf_pipeline_opts( # noqa: C901
request: ConvertDocumentsOptions,
) -> Tuple[PdfFormatOption, str]:
) -> Tuple[PdfFormatOption, bytes]:
if request.ocr_engine == OcrEngine.EASYOCR:
try:
import easyocr # noqa: F401
@@ -401,7 +401,7 @@ def get_pdf_pipeline_opts( # noqa: C901
serialized_data = _serialize_pdf_format_option(pdf_format_option)
options_hash = hashlib.sha1(serialized_data.encode()).hexdigest()
options_hash = hashlib.sha1(serialized_data.encode()).digest()
return pdf_format_option, options_hash