Skip to content

Commit ab545d9

Browse files
authored
Refactor testset_generator.py for newbies to understand easily (#207)
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
1 parent 75db229 commit ab545d9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/ragas/testset/testset_generator.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,17 @@ def generate(
281281
documents: list[LlamaindexDocument] | list[LangchainDocument],
282282
test_size: int,
283283
) -> TestDataset:
284+
if not isinstance(documents[0], (LlamaindexDocument, LangchainDocument)):
285+
raise ValueError(
286+
"Testset Generatation only supports LlamaindexDocuments or LangchainDocuments" # noqa
287+
)
288+
284289
if isinstance(documents[0], LangchainDocument):
285290
# cast to LangchainDocument since its the only case here
286291
documents = t.cast(list[LangchainDocument], documents)
287292
documents = [
288293
LlamaindexDocument.from_langchain_format(doc) for doc in documents
289294
]
290-
elif not isinstance(documents[0], LlamaindexDocument):
291-
raise ValueError(
292-
"Testset Generatation only supports LlamaindexDocuments or LangchainDocuments" # noqa
293-
)
294295
# Convert documents into nodes
295296
node_parser = SimpleNodeParser.from_defaults(
296297
chunk_size=self.chunk_size, chunk_overlap=0, include_metadata=True

0 commit comments

Comments
 (0)