-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand chunking testing, including new functional tests
This adds pytest-based functional tests to our repo with a basic PDF chunking test. While writing that test I discovered a minor bug in DocumentChunker, resulting in an additional unit test and a minor change to handle the case where we're given no documents and were previously not instantiating any chunker. Signed-off-by: Ben Browning <[email protected]>
- Loading branch information
Showing
6 changed files
with
81 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Standard | ||
import os | ||
from pathlib import Path | ||
|
||
# Third Party | ||
from openai import OpenAI | ||
|
||
# First Party | ||
from instructlab.sdg.utils.chunkers import DocumentChunker | ||
|
||
TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "testdata") | ||
|
||
openai_api_key = os.environ.get("OPENAI_API_KEY", "EMPTY") | ||
openai_api_base = os.environ.get("OPENAI_API_BASE", "http://localhost:8000/v1") | ||
|
||
# TODO: Apparently we don't really need any contents in the qna.yaml? | ||
knowledge_pdf_qna = """ | ||
version: 3 | ||
domain: astronomy | ||
""" | ||
|
||
def test_chunk_pdf(tmp_path): | ||
client = OpenAI( | ||
api_key=openai_api_key, | ||
base_url=openai_api_base, | ||
) | ||
|
||
qna_dir = os.path.join(tmp_path, "knowledge") | ||
os.makedirs(qna_dir) | ||
with open(os.path.join(qna_dir, "qna.yaml"), "w", encoding="utf-8") as f: | ||
f.write(knowledge_pdf_qna) | ||
|
||
leaf_node = [{ | ||
"documents": ["Lorem ipsum"], | ||
"filepaths": [Path(os.path.join(TEST_DATA_DIR, "phoenix.pdf"))], | ||
"taxonomy_path": "knowledge", | ||
}] | ||
chunker = DocumentChunker( | ||
leaf_node=leaf_node, | ||
taxonomy_path=tmp_path, | ||
output_dir=tmp_path, | ||
server_ctx_size=4096, | ||
chunk_word_count=500, | ||
tokenizer_model_name="instructlab/merlinite-7b-lab", | ||
) | ||
chunks = chunker.chunk_documents() | ||
assert len(chunks) > 1 | ||
assert "Phoenix is a minor constellation" in chunks[0] |
Binary file not shown.
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