9201ef759e
Harness Compat / harness compat (push) Failing after 0s
CI / test on 3.12 (standard) (push) Has been cancelled
CI / test on 3.13 (standard) (push) Has been cancelled
CI / test on 3.14 (standard) (push) Has been cancelled
CI / test on 3.10 (all-extras) (push) Has been cancelled
CI / test on 3.11 (all-extras) (push) Has been cancelled
CI / test on 3.12 (all-extras) (push) Has been cancelled
CI / test on 3.14 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.10 (pydantic-evals) (push) Has been cancelled
CI / test on 3.11 (pydantic-evals) (push) Has been cancelled
CI / test on 3.12 (pydantic-evals) (push) Has been cancelled
CI / deploy-docs-preview (push) Has been cancelled
CI / build release artifacts (push) Has been cancelled
CI / publish to PyPI (push) Has been cancelled
CI / Send tweet (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / mypy (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / test on 3.10 (standard) (push) Has been cancelled
CI / test on 3.11 (standard) (push) Has been cancelled
CI / test on 3.13 (all-extras) (push) Has been cancelled
CI / test on 3.14 (all-extras) (push) Has been cancelled
CI / test on 3.10 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.11 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.12 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.13 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.13 (pydantic-evals) (push) Has been cancelled
CI / test on 3.14 (pydantic-evals) (push) Has been cancelled
CI / test on 3.10 (lowest-versions) (push) Has been cancelled
CI / test on 3.11 (lowest-versions) (push) Has been cancelled
CI / test on 3.12 (lowest-versions) (push) Has been cancelled
CI / test on 3.13 (lowest-versions) (push) Has been cancelled
CI / test on 3.14 (lowest-versions) (push) Has been cancelled
CI / test examples on 3.11 (push) Has been cancelled
CI / test examples on 3.12 (push) Has been cancelled
CI / test examples on 3.13 (push) Has been cancelled
CI / test examples on 3.14 (push) Has been cancelled
CI / coverage (push) Has been cancelled
CI / check (push) Has been cancelled
CI / deploy-docs (push) Has been cancelled
70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
from dataclasses import dataclass
|
|
from datetime import timedelta
|
|
|
|
from pydantic_ai_examples.evals.models import (
|
|
TimeRangeBuilderSuccess,
|
|
TimeRangeInputs,
|
|
TimeRangeResponse,
|
|
)
|
|
from pydantic_evals.evaluators import (
|
|
Evaluator,
|
|
EvaluatorContext,
|
|
EvaluatorOutput,
|
|
)
|
|
from pydantic_evals.otel import SpanQuery
|
|
|
|
|
|
@dataclass
|
|
class ValidateTimeRange(Evaluator[TimeRangeInputs, TimeRangeResponse]):
|
|
def evaluate(
|
|
self, ctx: EvaluatorContext[TimeRangeInputs, TimeRangeResponse]
|
|
) -> EvaluatorOutput:
|
|
if isinstance(ctx.output, TimeRangeBuilderSuccess):
|
|
window_end = ctx.output.max_timestamp_with_offset
|
|
window_size = window_end - ctx.output.min_timestamp_with_offset
|
|
return {
|
|
'window_is_not_too_long': window_size <= timedelta(days=30),
|
|
'window_is_not_in_the_future': window_end <= ctx.inputs['now'],
|
|
}
|
|
|
|
return {} # No evaluation needed for errors
|
|
|
|
|
|
@dataclass
|
|
class UserMessageIsConcise(Evaluator[TimeRangeInputs, TimeRangeResponse]):
|
|
async def evaluate(
|
|
self,
|
|
ctx: EvaluatorContext[TimeRangeInputs, TimeRangeResponse],
|
|
) -> EvaluatorOutput:
|
|
if isinstance(ctx.output, TimeRangeBuilderSuccess):
|
|
user_facing_message = ctx.output.explanation
|
|
else:
|
|
user_facing_message = ctx.output.error_message
|
|
|
|
if user_facing_message is not None:
|
|
return len(user_facing_message.split()) < 50
|
|
else:
|
|
return {}
|
|
|
|
|
|
@dataclass
|
|
class AgentCalledTool(Evaluator[object, object, object]):
|
|
agent_name: str
|
|
tool_name: str
|
|
|
|
def evaluate(self, ctx: EvaluatorContext[object, object, object]) -> bool:
|
|
return ctx.span_tree.any(
|
|
SpanQuery(
|
|
name_equals='agent run',
|
|
has_attributes={'agent_name': self.agent_name},
|
|
stop_recursing_when=SpanQuery(name_equals='agent run'),
|
|
some_descendant_has=SpanQuery(
|
|
name_equals='running tool',
|
|
has_attributes={'gen_ai.tool.name': self.tool_name},
|
|
),
|
|
)
|
|
)
|
|
|
|
|
|
CUSTOM_EVALUATOR_TYPES = (ValidateTimeRange, UserMessageIsConcise, AgentCalledTool)
|