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

Hotfix/fix quickstart example for query creation #130

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions deepeval/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from deepeval.run_test import run_test
from deepeval.metrics.metric import Metric
from deepeval.test_case import LLMTestCase
from dataclasses import asdict


class EvaluationDataset(UserList):
Expand Down Expand Up @@ -230,7 +231,7 @@ def from_dict(
return cls(test_cases)

def to_dict(self):
return [x.dict() for x in self.data]
return [asdict(x) for x in self.data]

def to_csv(self, csv_filename: str):
import pandas as pd
Expand All @@ -255,7 +256,7 @@ def sample(self, n: int = 5):
if len(self.data) <= n:
n = len(self.data)
result = random.sample(self.data, n)
return [r.dict() for r in result]
return [asdict(r) for r in result]

def head(self, n: int = 5):
return self.data[:n]
Expand Down
5 changes: 3 additions & 2 deletions docs/docs/quickstart/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ Now we often don't want to write our own tests or at least be given a variety of
You can automatically create tests in DeepEval in just a few lines of code:

```python
from deepeval.dataset import create_evaluation_dataset
from deepeval.dataset import create_evaluation_query_answer_pairs

dataset = create_evaluation_query_answer_pairs(
openai_api_key="<YOUR_OPENAI_API_KEY>",
context="FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.7+ based on standard Python type hints.",
n=3
n=3,
)

```
Expand Down
12 changes: 12 additions & 0 deletions examples/create_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
from deepeval.dataset import (
create_evaluation_query_answer_pairs,
EvaluationDataset,
)

dataset: EvaluationDataset = create_evaluation_query_answer_pairs(
openai_api_key=os.environ["OPENAI_API_KEY"],
context="FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.7+ based on standard Python type hints.",
n=3,
)
dataset.review()
34 changes: 34 additions & 0 deletions examples/review_datasets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Define your completion protocol
import openai
from deepeval.dataset import EvaluationDataset
from deepeval.metrics.factual_consistency import FactualConsistencyMetric

ds = EvaluationDataset.from_csv(
"review-test.csv",
query_column="query",
expected_output_column="expected_output",
)
print(ds.sample())


def generate_chatgpt_output(query: str):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{
"role": "assistant",
"content": "The customer success phone line is 1200-231-231 and the customer success state is in Austin.",
},
{"role": "user", "content": query},
],
)
expected_output = response.choices[0].message.content
return expected_output


factual_consistency_metric = FactualConsistencyMetric()

ds.run_evaluation(
completion_fn=generate_chatgpt_output, metrics=[factual_consistency_metric]
)