mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
feat: Remove overall_eval_status calculation from _CustomMetricEvaluator and add threshold to custom metric function expected signature
Co-authored-by: Joseph Pagadora <jcpagadora@google.com> PiperOrigin-RevId: 861268984
This commit is contained in:
committed by
Copybara-Service
parent
85434e293f
commit
553e376718
@@ -24,7 +24,6 @@ from typing_extensions import override
|
||||
from .eval_case import ConversationScenario
|
||||
from .eval_case import Invocation
|
||||
from .eval_metrics import EvalMetric
|
||||
from .eval_metrics import EvalStatus
|
||||
from .evaluator import EvaluationResult
|
||||
from .evaluator import Evaluator
|
||||
|
||||
@@ -44,12 +43,6 @@ def _get_metric_function(
|
||||
) from e
|
||||
|
||||
|
||||
def _get_eval_status(score: Optional[float], threshold: float) -> EvalStatus:
|
||||
if score is None:
|
||||
return EvalStatus.NOT_EVALUATED
|
||||
return EvalStatus.PASSED if score >= threshold else EvalStatus.FAILED
|
||||
|
||||
|
||||
class _CustomMetricEvaluator(Evaluator):
|
||||
"""Evaluator for custom metrics."""
|
||||
|
||||
@@ -64,16 +57,20 @@ class _CustomMetricEvaluator(Evaluator):
|
||||
expected_invocations: Optional[list[Invocation]],
|
||||
conversation_scenario: Optional[ConversationScenario] = None,
|
||||
) -> EvaluationResult:
|
||||
eval_metric = self._eval_metric.model_copy(deep=True)
|
||||
eval_metric.threshold = None
|
||||
if inspect.iscoroutinefunction(self._metric_function):
|
||||
eval_result = await self._metric_function(
|
||||
actual_invocations, expected_invocations, conversation_scenario
|
||||
eval_metric,
|
||||
actual_invocations,
|
||||
expected_invocations,
|
||||
conversation_scenario,
|
||||
)
|
||||
else:
|
||||
eval_result = self._metric_function(
|
||||
actual_invocations, expected_invocations, conversation_scenario
|
||||
eval_metric,
|
||||
actual_invocations,
|
||||
expected_invocations,
|
||||
conversation_scenario,
|
||||
)
|
||||
|
||||
eval_result.overall_eval_status = _get_eval_status(
|
||||
eval_result.overall_score, self._eval_metric.threshold
|
||||
)
|
||||
return eval_result
|
||||
|
||||
@@ -258,9 +258,11 @@ class EvalMetric(EvalBaseModel):
|
||||
description="The name of the metric.",
|
||||
)
|
||||
|
||||
threshold: float = Field(
|
||||
threshold: Optional[float] = Field(
|
||||
default=None,
|
||||
description=(
|
||||
"A threshold value. Each metric decides how to interpret this"
|
||||
"This field will be deprecated soon. Please use `criterion` instead."
|
||||
" A threshold value. Each metric decides how to interpret this"
|
||||
" threshold."
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user