From b108b47d63f1baaed7bc264720345e7f2487f6d9 Mon Sep 17 00:00:00 2001 From: jjmachan Date: Tue, 10 Dec 2024 11:47:07 +0530 Subject: [PATCH] feat: load from annotated testset --- src/ragas/testset/synthesizers/testset_schema.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/ragas/testset/synthesizers/testset_schema.py b/src/ragas/testset/synthesizers/testset_schema.py index c05ae649b..02f7cadc4 100644 --- a/src/ragas/testset/synthesizers/testset_schema.py +++ b/src/ragas/testset/synthesizers/testset_schema.py @@ -158,3 +158,19 @@ def upload(self, base_url: str = RAGAS_API_URL, verbose: bool = True) -> str: if verbose: print(f"Testset uploaded! View at {testset_endpoint}") return testset_endpoint + + @classmethod + def from_annotated(cls, path: str) -> Testset: + """ + Loads a testset from an annotated JSON file from app.ragas.io. + """ + import json + + with open(path, "r") as f: + annotated_testset = json.load(f) + + samples = [] + for sample in annotated_testset: + if sample["approval_status"] == "approved": + samples.append(TestsetSample(**sample)) + return cls(samples=samples)