-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from enoch3712/68-add-critical-tests-to-run-in…
…-actions workflow and pytests added for critical run
- Loading branch information
Showing
3 changed files
with
76 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
import sys | ||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))) | ||
|
||
from dotenv import load_dotenv | ||
from extract_thinker import Process | ||
from extract_thinker.document_loader.document_loader_pypdf import DocumentLoaderPyPdf | ||
from extract_thinker.extractor import Extractor | ||
from extract_thinker.models.classification import Classification | ||
from tests.models.invoice import InvoiceContract | ||
from tests.models.driver_license import DriverLicense | ||
|
||
load_dotenv() | ||
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
INVOICE_PATH = os.path.join(CURRENT_DIR, '..', 'files', 'invoice.pdf') | ||
|
||
def test_critical_classification(): | ||
"""Critical test for basic classification""" | ||
# Setup | ||
document_loader = DocumentLoaderPyPdf() | ||
extractor = Extractor(document_loader) | ||
extractor.load_llm("groq/llama-3.1-70b-versatile") | ||
|
||
process = Process() | ||
process.add_classify_extractor([[extractor]]) | ||
|
||
classifications = [ | ||
Classification( | ||
name="Invoice", | ||
description="This is an invoice document", | ||
contract=InvoiceContract | ||
), | ||
Classification( | ||
name="Driver License", | ||
description="This is a driver license document", | ||
contract=DriverLicense | ||
) | ||
] | ||
|
||
# Act | ||
result = process.classify(INVOICE_PATH, classifications) | ||
|
||
# Assert | ||
assert result is not None | ||
assert result.name == "Invoice" |
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,27 @@ | ||
import os | ||
import sys | ||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))) | ||
|
||
from dotenv import load_dotenv | ||
from extract_thinker import Extractor | ||
from extract_thinker.document_loader.document_loader_pypdf import DocumentLoaderPyPdf | ||
from tests.models.invoice import InvoiceContract | ||
|
||
load_dotenv() | ||
cwd = os.getcwd() | ||
|
||
def test_critical_extract_with_pypdf(): | ||
"""Critical test for basic extraction functionality""" | ||
test_file_path = os.path.join(cwd, "tests", "files", "invoice.pdf") | ||
|
||
extractor = Extractor() | ||
extractor.load_document_loader(DocumentLoaderPyPdf()) | ||
extractor.load_llm("groq/llama-3.1-70b-versatile") | ||
|
||
result = extractor.extract(test_file_path, InvoiceContract) | ||
|
||
assert result is not None | ||
assert result.lines[0].description == "Consultation services" | ||
assert result.lines[0].quantity == 3 | ||
assert result.lines[0].unit_price == 375 | ||
assert result.lines[0].amount == 1125 |