Skip to content

. #841

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

Merged
merged 1 commit into from
Jun 20, 2024
Merged

. #841

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
1 change: 1 addition & 0 deletions deepeval/metrics/answer_relevancy/answer_relevancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(
strict_mode: bool = False,
verbose_mode: bool = False,
):
super().__init__()
self._statements: ContextVar[Optional[List[str]]] = ContextVar(
generate_uuid(), default=None
)
Expand Down
23 changes: 8 additions & 15 deletions deepeval/metrics/base_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,7 @@
from deepeval.utils import generate_uuid


class MetricMeta(type):
def __new__(cls, name, bases, attrs):
# Create the new class
new_class = super().__new__(cls, name, bases, attrs)
# Assign new ContextVar instances with unique identifiers
new_class._score = ContextVar(str(uuid.uuid4()), default=None)
new_class._score_breakdown = ContextVar(str(uuid.uuid4()), default=None)
new_class._reason = ContextVar(str(uuid.uuid4()), default=None)
new_class._success = ContextVar(str(uuid.uuid4()), default=None)
new_class._error = ContextVar(str(uuid.uuid4()), default=None)
return new_class


class BaseMetric(metaclass=MetricMeta):

class BaseMetric:
evaluation_model: Optional[str] = None
strict_mode: bool = False
async_mode: bool = True
Expand Down Expand Up @@ -85,6 +71,13 @@ def threshold(self) -> float:
def threshold(self, value: float):
self._threshold = value

def __init__(self):
self._score = ContextVar(str(uuid.uuid4()), default=None)
self._score_breakdown = ContextVar(str(uuid.uuid4()), default=None)
self._reason = ContextVar(str(uuid.uuid4()), default=None)
self._success = ContextVar(str(uuid.uuid4()), default=None)
self._error = ContextVar(str(uuid.uuid4()), default=None)

@abstractmethod
def measure(self, test_case: LLMTestCase, *args, **kwargs) -> float:
raise NotImplementedError
Expand Down
1 change: 1 addition & 0 deletions deepeval/metrics/bias/bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __init__(
strict_mode: bool = False,
verbose_mode: bool = False,
):
super().__init__()
self._opinions: ContextVar[Optional[List[str]]] = ContextVar(
generate_uuid(), default=None
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(
strict_mode: bool = False,
verbose_mode: bool = False,
):
super().__init__()
self._verdicts: ContextVar[
Optional[List[ContextualPrecisionVerdict]]
] = ContextVar(generate_uuid(), default=None)
Expand Down
1 change: 1 addition & 0 deletions deepeval/metrics/contextual_recall/contextual_recall.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(
strict_mode: bool = False,
verbose_mode: bool = False,
):
super().__init__()
self._verdicts: ContextVar[Optional[List[ContextualRecallVerdict]]] = (
ContextVar(generate_uuid(), default=None)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(
strict_mode: bool = False,
verbose_mode: bool = False,
):
super().__init__()
self._verdicts: ContextVar[
Optional[List[ContextualRelevancyVerdict]]
] = ContextVar(generate_uuid(), default=None)
Expand Down
1 change: 1 addition & 0 deletions deepeval/metrics/faithfulness/faithfulness.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def __init__(
strict_mode: bool = False,
verbose_mode: bool = False,
):
super().__init__()
self._truths: ContextVar[Optional[List[str]]] = ContextVar(
generate_uuid(), default=None
)
Expand Down
1 change: 1 addition & 0 deletions deepeval/metrics/g_eval/g_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def __init__(
strict_mode: bool = False,
verbose_mode: bool = False,
):
super().__init__()
self._evaluation_steps: ContextVar[Optional[List[str]]] = ContextVar(
generate_uuid(), default=None
)
Expand Down
1 change: 1 addition & 0 deletions deepeval/metrics/hallucination/hallucination.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(
strict_mode: bool = False,
verbose_mode: bool = False,
):
super().__init__()
self._verdicts: ContextVar[Optional[List[HallucinationVerdict]]] = (
ContextVar(generate_uuid(), default=None)
)
Expand Down
1 change: 1 addition & 0 deletions deepeval/metrics/summarization/summarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def __init__(
strict_mode: bool = False,
verbose_mode: bool = False,
):
super().__init__()
self._truths: ContextVar[Optional[List[str]]] = ContextVar(
generate_uuid(), default=None
)
Expand Down
1 change: 1 addition & 0 deletions deepeval/metrics/toxicity/toxicity.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __init__(
strict_mode: bool = False,
verbose_mode: bool = False,
):
super().__init__()
self._opinions: ContextVar[Optional[List[str]]] = ContextVar(
generate_uuid(), default=None
)
Expand Down
23 changes: 18 additions & 5 deletions tests/test_everything.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ def test_everything():
verbose_mode=verbose_mode,
)

metric11 = GEval(
name="Relevancy",
criteria="Relevancy - determine if the actual output is relevant with the input.",
evaluation_params=[
LLMTestCaseParams.INPUT,
LLMTestCaseParams.ACTUAL_OUTPUT,
],
strict_mode=strict_mode,
model="gpt-4-0125-preview",
verbose_mode=verbose_mode,
)

test_case = LLMTestCase(
input="What is this",
actual_output="this is a latte",
Expand All @@ -140,15 +152,16 @@ def test_everything():
test_case,
[
metric1,
metric2,
metric3,
metric4,
metric5,
# metric2,
# metric3,
# metric4,
# metric5,
# metric6,
# metric7,
# metric8,
# metric9,
# metric10,
metric10,
metric11,
],
# run_async=False,
)
Expand Down
Loading