Skip to content

Commit

Permalink
Refactor testset_generator.py for newbies to understand easily (#207)
Browse files Browse the repository at this point in the history
Hi

I totally understand original code is correct.
But I think my suggestion is much easier to understand.

If you feel it is too much, you can ignore
  • Loading branch information
Yongtae723 authored Oct 23, 2023
1 parent 75db229 commit ab545d9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/ragas/testset/testset_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,17 @@ def generate(
documents: list[LlamaindexDocument] | list[LangchainDocument],
test_size: int,
) -> TestDataset:
if not isinstance(documents[0], (LlamaindexDocument, LangchainDocument)):
raise ValueError(
"Testset Generatation only supports LlamaindexDocuments or LangchainDocuments" # noqa
)

if isinstance(documents[0], LangchainDocument):
# cast to LangchainDocument since its the only case here
documents = t.cast(list[LangchainDocument], documents)
documents = [
LlamaindexDocument.from_langchain_format(doc) for doc in documents
]
elif not isinstance(documents[0], LlamaindexDocument):
raise ValueError(
"Testset Generatation only supports LlamaindexDocuments or LangchainDocuments" # noqa
)
# Convert documents into nodes
node_parser = SimpleNodeParser.from_defaults(
chunk_size=self.chunk_size, chunk_overlap=0, include_metadata=True
Expand Down

0 comments on commit ab545d9

Please sign in to comment.