|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from trpc_agent_sdk.evaluation import AgentEvaluator |
| 6 | +from trpc_agent_sdk.evaluation._agent_evaluator import _EvalExecuter |
| 7 | +from trpc_agent_sdk.evaluation._agent_evaluator import _EvaluationCasesFailed |
| 8 | + |
| 9 | +_ORIGINAL_AGENT_EVALUATE = AgentEvaluator.evaluate |
| 10 | +_ORIGINAL_EXECUTER_EVALUATE = _EvalExecuter.evaluate |
| 11 | + |
| 12 | + |
| 13 | +def _log_threshold_failure(exc: _EvaluationCasesFailed) -> None: |
| 14 | + print( |
| 15 | + "\n[examples/evaluation] Threshold not met; treating as non-fatal for example smoke tests.", |
| 16 | + flush=True, |
| 17 | + ) |
| 18 | + print(exc, flush=True) |
| 19 | + |
| 20 | + |
| 21 | +async def _safe_agent_evaluate(*args, **kwargs): |
| 22 | + try: |
| 23 | + return await _ORIGINAL_AGENT_EVALUATE(*args, **kwargs) |
| 24 | + except _EvaluationCasesFailed as exc: |
| 25 | + _log_threshold_failure(exc) |
| 26 | + return None |
| 27 | + |
| 28 | + |
| 29 | +async def _safe_executer_evaluate(self, *args, **kwargs): |
| 30 | + try: |
| 31 | + return await _ORIGINAL_EXECUTER_EVALUATE(self, *args, **kwargs) |
| 32 | + except _EvaluationCasesFailed as exc: |
| 33 | + _log_threshold_failure(exc) |
| 34 | + return None |
| 35 | + |
| 36 | + |
| 37 | +@pytest.fixture(autouse=True) |
| 38 | +def _ignore_threshold_failures(monkeypatch: pytest.MonkeyPatch) -> None: |
| 39 | + monkeypatch.setattr(AgentEvaluator, "evaluate", staticmethod(_safe_agent_evaluate)) |
| 40 | + monkeypatch.setattr(_EvalExecuter, "evaluate", _safe_executer_evaluate) |
0 commit comments