Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gpt synthetic data #74

Merged
merged 10 commits into from
Sep 1, 2023
28 changes: 27 additions & 1 deletion deepeval/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .metrics.metric import Metric
from .query_generator import BEIRQueryGenerator
from .retry import retry
import openai


class EvaluationDataset(UserList):
Expand Down Expand Up @@ -237,7 +238,6 @@ def create_evaluation_dataset_from_raw_text(text: str, output_fn: str = "output.

# NOTE: loading this may take a while as the model used is quite big
gen = BEIRQueryGenerator()
text = "Synthetic queries are useful for scenraios where there is no data."
queries = gen.generate_queries(texts=[text], num_queries=2)
test_cases = []
with open(output_fn, "w") as f:
Expand All @@ -249,3 +249,29 @@ def create_evaluation_dataset_from_raw_text(text: str, output_fn: str = "output.

dataset = EvaluationDataset(test_cases=test_cases)
return dataset

def create_evaluation_query_output_pairs(text: str, n:int = 3):
"""Utility function to create an evaluation dataset using GPT."""

prompt = f"""
Please generate {n} queries that may lead to the following text as an output. Ensure diversity in the generated queries.

{text}
"""

queries = openai.Completion.create(
engine="gpt-3.5-turbo",
prompt=prompt,
temperature=0,
)

test_cases = []
for query_choice in queries.choices:
generated_query = query_choice.message['content']
test_case = TestCase(query=generated_query, expected_output=text)
test_cases.append(test_case)

dataset = EvaluationDataset(test_cases=test_cases)
return dataset