Skip to content

Commit 9e69cac

Browse files
committed
.
1 parent b76570e commit 9e69cac

File tree

6 files changed

+44
-5
lines changed

6 files changed

+44
-5
lines changed

deepeval/dataset/api.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
from deepeval.dataset.golden import Golden, ConversationalGolden
55

66

7+
def to_snake_case(string: str) -> str:
8+
return "".join(
9+
["_" + i.lower() if i.isupper() else i for i in string]
10+
).lstrip("_")
11+
12+
713
class APIDataset(BaseModel):
814
alias: str
915
overwrite: bool
@@ -18,7 +24,7 @@ class CreateDatasetHttpResponse(BaseModel):
1824

1925

2026
class DatasetHttpResponse(BaseModel):
21-
goldens: List[Golden]
27+
goldens: List[Golden] = Field(alias="goldens")
2228
conversational_goldens: List[ConversationalGolden] = Field(
2329
alias="conversationalGoldens"
2430
)

deepeval/dataset/dataset.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
)
2424
from deepeval.dataset.golden import Golden, ConversationalGolden
2525
from deepeval.test_case import LLMTestCase, ConversationalTestCase
26-
from deepeval.utils import is_confident
26+
from deepeval.utils import convert_keys_to_snake_case, is_confident
2727
from deepeval.synthesizer.base_synthesizer import BaseSynthesizer
2828

2929
valid_file_types = ["csv", "json"]
@@ -365,8 +365,10 @@ def pull(self, alias: str, auto_convert_goldens_to_test_cases: bool = True):
365365
)
366366

367367
response = DatasetHttpResponse(
368-
goldens=result["goldens"],
369-
conversationalGoldens=result["conversationalGoldens"],
368+
goldens=convert_keys_to_snake_case(result["goldens"]),
369+
conversationalGoldens=convert_keys_to_snake_case(
370+
result["conversationalGoldens"]
371+
),
370372
datasetId=result["datasetId"],
371373
)
372374

deepeval/dataset/golden.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
from typing import Optional, Dict, List
33

44

5+
def to_snake_case(string: str) -> str:
6+
return "".join(
7+
["_" + i.lower() if i.isupper() else i for i in string]
8+
).lstrip("_")
9+
10+
511
class Golden(BaseModel):
612
input: str
713
actual_output: Optional[str] = Field(
@@ -27,5 +33,7 @@ class ConversationalGolden(BaseModel):
2733
)
2834
comments: Optional[str] = Field(None)
2935
messages: List[Golden] = Field(
30-
default_factory=lambda: [], serialization_alias="goldens"
36+
default_factory=lambda: [],
37+
validation_alias="goldens",
38+
serialization_alias="goldens",
3139
)

deepeval/metrics/ragas.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def __init__(
9292
model: Optional[Union[str, BaseChatModel]] = "gpt-3.5-turbo",
9393
_track: bool = True,
9494
):
95+
super.__init__()
9596
self.threshold = threshold
9697
self.model = model
9798
self._track = _track
@@ -160,6 +161,7 @@ def __init__(
160161
embeddings: Optional[Embeddings] = None,
161162
_track: bool = True,
162163
):
164+
super.__init__()
163165
self.threshold = threshold
164166
self.model = model
165167
self._track = _track
@@ -226,6 +228,7 @@ def __init__(
226228
model: Optional[Union[str, BaseChatModel]] = "gpt-3.5-turbo",
227229
_track: bool = True,
228230
):
231+
super.__init__()
229232
self.threshold = threshold
230233
self.model = model
231234
self._track = _track
@@ -287,6 +290,7 @@ def __init__(
287290
model: Optional[Union[str, BaseChatModel]] = "gpt-3.5-turbo",
288291
_track: bool = True,
289292
):
293+
super.__init__()
290294
self.threshold = threshold
291295
self.model = model
292296
self._track = _track
@@ -348,6 +352,7 @@ def __init__(
348352
model: Optional[Union[str, BaseChatModel]] = "gpt-3.5-turbo",
349353
embeddings: Optional[Embeddings] = None,
350354
):
355+
super.__init__()
351356
self.threshold = threshold
352357
self.model = model
353358
if isinstance(model, str):

deepeval/utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@
2020
from deepeval.key_handler import KeyValues, KEY_FILE_HANDLER
2121

2222

23+
def camel_to_snake(name: str) -> str:
24+
s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", name)
25+
return re.sub("([a-z0-9])([A-Z])", r"\1_\2", s1).lower()
26+
27+
28+
def convert_keys_to_snake_case(data: Any) -> Any:
29+
if isinstance(data, dict):
30+
return {
31+
camel_to_snake(k): convert_keys_to_snake_case(v)
32+
for k, v in data.items()
33+
}
34+
elif isinstance(data, list):
35+
return [convert_keys_to_snake_case(i) for i in data]
36+
else:
37+
return data
38+
39+
2340
def prettify_list(lst: List[Any]):
2441
if len(lst) == 0:
2542
return "[]"

tests/test_deployment.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class FakeMetric(BaseMetric):
1212
# This metric by default checks if the latency is greater than 10 seconds
1313
def __init__(self, threshold: float = 0.5):
14+
super().__init__()
1415
self.threshold = threshold
1516

1617
def measure(self, test_case: LLMTestCase):

0 commit comments

Comments
 (0)