Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/confident-ai/deepeval into …
Browse files Browse the repository at this point in the history
…anindya/harness
  • Loading branch information
Anindyadeep committed Mar 10, 2024
2 parents 097fe65 + 215a1ba commit 9090c34
Show file tree
Hide file tree
Showing 71 changed files with 3,016 additions and 1,595 deletions.
10 changes: 5 additions & 5 deletions deepeval/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
# Optionally add telemtry
from ._version import __version__

from .decorators.hyperparameters import set_hyperparameters
from deepeval.event import track
from deepeval.evaluate import evaluate, run_test, assert_test
from deepeval.test_run import on_test_run_end
from deepeval.evaluate import evaluate, assert_test
from deepeval.test_run import on_test_run_end, log_hyperparameters
from deepeval.utils import login_with_confident_api_key
from deepeval.telemetry import *

__all__ = [
"set_hyperparameters",
"login_with_confident_api_key",
"log_hyperparameters",
"track",
"evaluate",
"run_test",
"assert_test",
"on_test_run_end",
]
Expand Down
2 changes: 1 addition & 1 deletion deepeval/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__: str = "0.20.78"
__version__: str = "0.20.85"
6 changes: 1 addition & 5 deletions deepeval/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import typer
from typing_extensions import Annotated

# Rich has a few dependency issues
try:
from rich import print
except Exception as e:
pass
from rich import print
from deepeval.key_handler import KEY_FILE_HANDLER, KeyValues
from deepeval.cli.test import app as test_app
from typing import Optional
Expand Down
58 changes: 58 additions & 0 deletions deepeval/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
from dataclasses import dataclass
from rich.console import Console
import json
import csv
import webbrowser
import os
import datetime

from deepeval.metrics import BaseMetric
from deepeval.api import Api, Endpoints
Expand All @@ -20,6 +23,8 @@
from deepeval.utils import is_confident
from deepeval.synthesizer.base_synthesizer import BaseSynthesizer

valid_file_types = ["csv", "json"]


@dataclass
class EvaluationDataset:
Expand Down Expand Up @@ -335,3 +340,56 @@ def generate_goldens(
self.goldens.extend(
synthesizer.generate_goldens(contexts, max_goldens_per_context)
)

# TODO: add save test cases as well
def save_as(self, file_type: str, directory: str):
if file_type not in valid_file_types:
raise ValueError(
f"Invalid file type. Available file types to save as: {', '.join(type for type in valid_file_types)}"
)

if len(self.goldens) == 0:
raise ValueError(
f"No synthetic goldens found. Please generate goldens before attempting to save data as {file_type}"
)

new_filename = (
datetime.datetime.now().strftime("%Y%m%d_%H%M%S") + f".{file_type}"
)

if not os.path.exists(directory):
os.makedirs(directory)

full_file_path = os.path.join(directory, new_filename)

if file_type == "json":
with open(full_file_path, "w") as file:
json_data = [
{
"input": golden.input,
"actual_output": golden.actual_output,
"expected_output": golden.expected_output,
"context": golden.context,
}
for golden in self.goldens
]
json.dump(json_data, file, indent=4)

elif file_type == "csv":
with open(full_file_path, "w", newline="") as file:
writer = csv.writer(file)
writer.writerow(
["input", "actual_output", "expected_output", "context"]
)
for golden in self.goldens:
context_str = "|".join(golden.context)
writer.writerow(
[
golden.input,
golden.actual_output,
golden.expected_output,
context_str,
]
)

print(f"Evaluation dataset saved at {full_file_path}!")
Empty file removed deepeval/decorators/__init__.py
Empty file.
37 changes: 0 additions & 37 deletions deepeval/decorators/hyperparameters.py

This file was deleted.

Loading

0 comments on commit 9090c34

Please sign in to comment.