Skip to content

port 4llm functions to PyMuPDF API - #5172

Open
JorjMcKie wants to merge 1 commit into
mainfrom
4llm-function-ports
Open

JorjMcKie wants to merge 1 commit into
mainfrom
4llm-function-ports

Conversation

@JorjMcKie

Copy link
Copy Markdown
Collaborator

This fix makes the pymupdf4llm functions available in PyMuPDF's API.

This fix makes the pymupdf4llm functions available in PyMuPDF's API.
Comment on lines +5 to +6
use_layout = util._use_layout() and hasattr(pymupdf, "layout")
use_4llm = util._use_4llm() and hasattr(pymupdf, "pymupdf4llm")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must not use things like hasattr() in tests. If util._use_layout() returns true, then it is an error if pymupdf.layout does not exist.

So i think we should just use util._use_layout() directly in the test.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok - will remove this then, including the checks in the test function itself.

Comment on lines +10 to +12
if pymupdf.__version__ < "2.0":
print(f"not testing version < {pymupdf.__version__}")
return

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't generally expect to run pymupdf tests on a different version of pymupdf, and i don't think any other tests check the pymupdf version like this. So this could be removed i think.

Comment on lines +42 to +47
if use_layout:
print("not testing: layout feature available")
return
if not use_4llm:
print("not testing: 4llm feature not available")
return

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently only make release wheels that either have both layout and 4llm (pymupdf), or neither layout or 4llm (pymupdf-lite).

So i'm not sure this test is useful? Were you expecting pymupdf-lite to contain pymupdf4llm code?

Comment thread src/__init__.py
Document.to_json = _to_json # noqa: F401
Document.to_chunks = _to_chunks # noqa: F401
convert_batch = _convert_batch # noqa: F401
use_layout = _use_layout # noqa: F401

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This setting of use_layout seems new - what is it used for?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does a user disable the use of layout?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants