-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #414 from confident-ai/feature/cost-latency
added latency and cost metric
- Loading branch information
Showing
9 changed files
with
78 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from deepeval.metrics import BaseMetric | ||
from deepeval.test_case import LLMTestCase | ||
|
||
|
||
class CostMetric(BaseMetric): | ||
def __init__(self, threshold: float): | ||
self.threshold = threshold | ||
|
||
def measure(self, test_case: LLMTestCase): | ||
self.success = test_case.cost <= self.threshold | ||
self.score = test_case.cost | ||
return self.score | ||
|
||
def is_successful(self): | ||
return self.success | ||
|
||
@property | ||
def __name__(self): | ||
return "Cost" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from deepeval.metrics import BaseMetric | ||
from deepeval.test_case import LLMTestCase | ||
|
||
|
||
class LatencyMetric(BaseMetric): | ||
def __init__(self, threshold: float): | ||
self.threshold = threshold | ||
|
||
def measure(self, test_case: LLMTestCase): | ||
self.success = test_case.latency <= self.threshold | ||
self.score = test_case.latency | ||
return self.score | ||
|
||
def is_successful(self): | ||
return self.success | ||
|
||
@property | ||
def __name__(self): | ||
return "Latency" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from deepeval.metrics import CostMetric | ||
from deepeval.test_case import LLMTestCase | ||
from deepeval import assert_test | ||
|
||
|
||
def test_cost_metric(): | ||
metric = CostMetric(threshold=12) | ||
test_case = LLMTestCase(input="...", actual_output="...", cost=12) | ||
assert_test(test_case, [metric]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from deepeval.metrics import LatencyMetric | ||
from deepeval.test_case import LLMTestCase | ||
from deepeval import assert_test | ||
|
||
|
||
def test_latency_metric(): | ||
metric = LatencyMetric(threshold=12) | ||
test_case = LLMTestCase( | ||
input="...", | ||
actual_output="...", | ||
latency=8.3, | ||
) | ||
assert_test(test_case, [metric]) |