Skip to content

Commit 90ddcd9

Browse files
committed
.
1 parent be06095 commit 90ddcd9

File tree

12 files changed

+36
-20
lines changed

12 files changed

+36
-20
lines changed

deepeval/metrics/answer_relevancy/answer_relevancy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def __init__(
6161
strict_mode: bool = False,
6262
verbose_mode: bool = False,
6363
):
64+
super().__init__()
6465
self._statements: ContextVar[Optional[List[str]]] = ContextVar(
6566
generate_uuid(), default=None
6667
)

deepeval/metrics/base_metric.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,7 @@
77
from deepeval.utils import generate_uuid
88

99

10-
class MetricMeta(type):
11-
def __new__(cls, name, bases, attrs):
12-
# Create the new class
13-
new_class = super().__new__(cls, name, bases, attrs)
14-
# Assign new ContextVar instances with unique identifiers
15-
new_class._score = ContextVar(str(uuid.uuid4()), default=None)
16-
new_class._score_breakdown = ContextVar(str(uuid.uuid4()), default=None)
17-
new_class._reason = ContextVar(str(uuid.uuid4()), default=None)
18-
new_class._success = ContextVar(str(uuid.uuid4()), default=None)
19-
new_class._error = ContextVar(str(uuid.uuid4()), default=None)
20-
return new_class
21-
22-
23-
class BaseMetric(metaclass=MetricMeta):
24-
10+
class BaseMetric:
2511
evaluation_model: Optional[str] = None
2612
strict_mode: bool = False
2713
async_mode: bool = True
@@ -85,6 +71,13 @@ def threshold(self) -> float:
8571
def threshold(self, value: float):
8672
self._threshold = value
8773

74+
def __init__(self):
75+
self._score = ContextVar(str(uuid.uuid4()), default=None)
76+
self._score_breakdown = ContextVar(str(uuid.uuid4()), default=None)
77+
self._reason = ContextVar(str(uuid.uuid4()), default=None)
78+
self._success = ContextVar(str(uuid.uuid4()), default=None)
79+
self._error = ContextVar(str(uuid.uuid4()), default=None)
80+
8881
@abstractmethod
8982
def measure(self, test_case: LLMTestCase, *args, **kwargs) -> float:
9083
raise NotImplementedError

deepeval/metrics/bias/bias.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __init__(
6363
strict_mode: bool = False,
6464
verbose_mode: bool = False,
6565
):
66+
super().__init__()
6667
self._opinions: ContextVar[Optional[List[str]]] = ContextVar(
6768
generate_uuid(), default=None
6869
)

deepeval/metrics/contextual_precision/contextual_precision.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__(
5858
strict_mode: bool = False,
5959
verbose_mode: bool = False,
6060
):
61+
super().__init__()
6162
self._verdicts: ContextVar[
6263
Optional[List[ContextualPrecisionVerdict]]
6364
] = ContextVar(generate_uuid(), default=None)

deepeval/metrics/contextual_recall/contextual_recall.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def __init__(
5555
strict_mode: bool = False,
5656
verbose_mode: bool = False,
5757
):
58+
super().__init__()
5859
self._verdicts: ContextVar[Optional[List[ContextualRecallVerdict]]] = (
5960
ContextVar(generate_uuid(), default=None)
6061
)

deepeval/metrics/contextual_relevancy/contextual_relevancy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def __init__(
5757
strict_mode: bool = False,
5858
verbose_mode: bool = False,
5959
):
60+
super().__init__()
6061
self._verdicts: ContextVar[
6162
Optional[List[ContextualRelevancyVerdict]]
6263
] = ContextVar(generate_uuid(), default=None)

deepeval/metrics/faithfulness/faithfulness.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def __init__(
7272
strict_mode: bool = False,
7373
verbose_mode: bool = False,
7474
):
75+
super().__init__()
7576
self._truths: ContextVar[Optional[List[str]]] = ContextVar(
7677
generate_uuid(), default=None
7778
)

deepeval/metrics/g_eval/g_eval.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def __init__(
8080
strict_mode: bool = False,
8181
verbose_mode: bool = False,
8282
):
83+
super().__init__()
8384
self._evaluation_steps: ContextVar[Optional[List[str]]] = ContextVar(
8485
generate_uuid(), default=None
8586
)

deepeval/metrics/hallucination/hallucination.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def __init__(
5555
strict_mode: bool = False,
5656
verbose_mode: bool = False,
5757
):
58+
super().__init__()
5859
self._verdicts: ContextVar[Optional[List[HallucinationVerdict]]] = (
5960
ContextVar(generate_uuid(), default=None)
6061
)

deepeval/metrics/summarization/summarization.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def __init__(
117117
strict_mode: bool = False,
118118
verbose_mode: bool = False,
119119
):
120+
super().__init__()
120121
self._truths: ContextVar[Optional[List[str]]] = ContextVar(
121122
generate_uuid(), default=None
122123
)

deepeval/metrics/toxicity/toxicity.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __init__(
6363
strict_mode: bool = False,
6464
verbose_mode: bool = False,
6565
):
66+
super().__init__()
6667
self._opinions: ContextVar[Optional[List[str]]] = ContextVar(
6768
generate_uuid(), default=None
6869
)

tests/test_everything.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ def test_everything():
128128
verbose_mode=verbose_mode,
129129
)
130130

131+
metric11 = GEval(
132+
name="Relevancy",
133+
criteria="Relevancy - determine if the actual output is relevant with the input.",
134+
evaluation_params=[
135+
LLMTestCaseParams.INPUT,
136+
LLMTestCaseParams.ACTUAL_OUTPUT,
137+
],
138+
strict_mode=strict_mode,
139+
model="gpt-4-0125-preview",
140+
verbose_mode=verbose_mode,
141+
)
142+
131143
test_case = LLMTestCase(
132144
input="What is this",
133145
actual_output="this is a latte",
@@ -140,15 +152,16 @@ def test_everything():
140152
test_case,
141153
[
142154
metric1,
143-
metric2,
144-
metric3,
145-
metric4,
146-
metric5,
155+
# metric2,
156+
# metric3,
157+
# metric4,
158+
# metric5,
147159
# metric6,
148160
# metric7,
149161
# metric8,
150162
# metric9,
151-
# metric10,
163+
metric10,
164+
metric11,
152165
],
153166
# run_async=False,
154167
)

0 commit comments

Comments
 (0)