-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab910fa
commit 42d8ab9
Showing
7 changed files
with
68 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
|
||
from marker.processors.llm.llm_meta import LLMSimpleBlockMetaProcessor | ||
from marker.processors.llm.llm_text import LLMTextProcessor | ||
from marker.schema import BlockTypes | ||
|
||
|
||
@pytest.mark.filename("adversarial.pdf") | ||
@pytest.mark.config({"page_range": [0], "use_llm": True}) | ||
def test_llm_text_processor(pdf_document, mocker): | ||
# Get all inline math lines | ||
text_lines = pdf_document.contained_blocks((BlockTypes.Line,)) | ||
text_lines = [line for line in text_lines if line.formats and "math" in line.formats] | ||
assert len(text_lines) == 3 | ||
corrected_lines = ["<math>Text</math>"] * len(text_lines) | ||
|
||
mock_cls = Mock() | ||
mock_cls.return_value.generate_response.return_value = {"corrected_lines": corrected_lines} | ||
mocker.patch("marker.processors.llm.GoogleModel", mock_cls) | ||
|
||
config = {"use_llm": True, "google_api_key": "test"} | ||
processor_lst = [LLMTextProcessor(config)] | ||
processor = LLMSimpleBlockMetaProcessor(processor_lst, config) | ||
processor(pdf_document) | ||
|
||
contained_spans = text_lines[0].contained_blocks(pdf_document, (BlockTypes.Span,)) | ||
assert contained_spans[0].text == "Text\n" # Newline inserted at end of line | ||
assert contained_spans[0].formats == ["math"] | ||
|
||
|
||
@pytest.mark.filename("adversarial.pdf") | ||
@pytest.mark.config({"page_range": [0]}) | ||
def test_llm_text_processor_disabled(pdf_document): | ||
# Get all inline math lines | ||
text_lines = pdf_document.contained_blocks((BlockTypes.Line,)) | ||
text_lines = [line for line in text_lines if line.formats and "math" in line.formats] | ||
assert len(text_lines) == 0 | ||
|
||
|
||
@pytest.mark.filename("adversarial.pdf") | ||
@pytest.mark.config({"page_range": [0], "texify_inline_spans": True}) | ||
def test_llm_text_processor_texify(pdf_document): | ||
# Get all inline math lines | ||
text_lines = pdf_document.contained_blocks((BlockTypes.Line,)) | ||
text_lines = [line for line in text_lines if line.formats and "math" in line.formats] | ||
assert len(text_lines) == 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters