mirror of
https://github.com/VectifyAI/PageIndex.git
synced 2026-06-21 20:18:09 +02:00
Move pdf_parser off doc dict, pass via call args
This commit is contained in:
parent
ec1aaca4c9
commit
108cb28518
2 changed files with 5 additions and 9 deletions
|
|
@ -32,7 +32,7 @@ def _count_pages(doc_info: dict) -> int:
|
|||
return get_number_of_pages(doc_info['path'])
|
||||
|
||||
|
||||
def _get_pdf_page_content(doc_info: dict, page_nums: list[int]) -> list[dict]:
|
||||
def _get_pdf_page_content(doc_info: dict, page_nums: list[int], pdf_parser: str = DEFAULT_PDF_PARSER) -> list[dict]:
|
||||
"""Extract text for specific PDF pages (1-indexed). Prefer cached pages, fallback to PDF."""
|
||||
cached_pages = doc_info.get('pages')
|
||||
if cached_pages:
|
||||
|
|
@ -41,8 +41,7 @@ def _get_pdf_page_content(doc_info: dict, page_nums: list[int]) -> list[dict]:
|
|||
{'page': p, 'content': page_map[p]}
|
||||
for p in page_nums if p in page_map
|
||||
]
|
||||
parser = doc_info.get('pdf_parser') or DEFAULT_PDF_PARSER
|
||||
all_pages = read_pdf_pages(doc_info['path'], pdf_parser=parser)
|
||||
all_pages = read_pdf_pages(doc_info['path'], pdf_parser=pdf_parser)
|
||||
total = len(all_pages)
|
||||
valid_pages = [p for p in page_nums if 1 <= p <= total]
|
||||
return [
|
||||
|
|
@ -105,7 +104,7 @@ def get_document_structure(documents: dict, doc_id: str) -> str:
|
|||
return json.dumps(structure_no_text, ensure_ascii=False)
|
||||
|
||||
|
||||
def get_page_content(documents: dict, doc_id: str, pages: str) -> str:
|
||||
def get_page_content(documents: dict, doc_id: str, pages: str, pdf_parser: str = DEFAULT_PDF_PARSER) -> str:
|
||||
"""
|
||||
Retrieve page content for a document.
|
||||
|
||||
|
|
@ -126,7 +125,7 @@ def get_page_content(documents: dict, doc_id: str, pages: str) -> str:
|
|||
|
||||
try:
|
||||
if doc_info.get('type') == 'pdf':
|
||||
content = _get_pdf_page_content(doc_info, page_nums)
|
||||
content = _get_pdf_page_content(doc_info, page_nums, pdf_parser=pdf_parser)
|
||||
else:
|
||||
content = _get_md_page_content(doc_info, page_nums)
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue