Skip to content

Commit

Permalink
Merge pull request #53 from confident-ai/feature/fix-custom-metric
Browse files Browse the repository at this point in the history
Add custom metric
  • Loading branch information
jwongster2 authored Aug 25, 2023
2 parents bd44714 + 2bebc58 commit c8296c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
11 changes: 4 additions & 7 deletions docs/docs/quickstart/custom-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ As of right now, we do not currently support custom metrics for our dashboard bu
:::

```python
import asyncio
from deepeval.metrics.metric import Metric

class LengthMetric(Metric):
Expand All @@ -20,18 +19,15 @@ class LengthMetric(Metric):
def measure(self, text: str):
# sends to server
score = len(text)
self.success = score > minimum_length
self.success = score > self.minimum_length
# Optional: Logs it to the server
self.log(
query=text,
success=success
score=score/100, # just to have something here - should be between 0 and 1
success=self.success
)
return score

def measure(self, text: str):
self.success = len(x) > self.minimum_length
return a > b

def is_successful(self):
return self.success

Expand All @@ -40,4 +36,5 @@ class LengthMetric(Metric):
return "Length"

metric = LengthMetric()

```
22 changes: 8 additions & 14 deletions tests/test_custom_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,17 @@ class LengthMetric(Metric):
def __init__(self, minimum_length: int = 3):
self.minimum_length = minimum_length

def __call__(self, text: str):
# sends to server
score = self.measure(text)
# Optional: Logs it to the server
asyncio.create_task(
self._send_to_server(
metric_score=score,
metric_name=self.__name__,
query=text,
success=self.success,
)
)
return self.measure(text)

def measure(self, text: str):
# sends to server
score = len(text)
self.success = score > self.minimum_length
# Optional: Logs it to the server
self.log(
query=text,
score=score
/ 100, # just to have something here - should be between 0 and 1
success=self.success,
)
return score

def is_successful(self):
Expand Down

0 comments on commit c8296c1

Please sign in to comment.