Three near-identical Turn(...)+save_turn blocks (send-fail / poll-except / happy path) collapse into one _persist_turn helper differing only by the optional fields set. The期望→隐式规则 translation becomes a pure, unit-testable derive_implicit_rules seam (CONTEXT: 期望与规则叠加生效), and the rule_type→ModelPurpose map is hoisted to a module constant.
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
"""Translate a case's期望 (Expectation) into implicit评估规则.
|
||
|
||
期望描述"想要什么",评估规则是"怎么判定"——期望派生的隐式规则与显式规则
|
||
叠加生效(CONTEXT.md)。此翻译是纯逻辑,独立于规则执行与持久化,便于单测。
|
||
"""
|
||
|
||
from agenteval.models import EvalRuleConfig, Expectation
|
||
|
||
|
||
def derive_implicit_rules(expectation: Expectation) -> list[EvalRuleConfig]:
|
||
"""Build the implicit rule configs a case's expectation implies."""
|
||
rules: list[EvalRuleConfig] = []
|
||
if expectation.response_time_max_ms:
|
||
rules.append(
|
||
EvalRuleConfig(
|
||
type="response_time",
|
||
params={"max_ms": expectation.response_time_max_ms},
|
||
)
|
||
)
|
||
if expectation.keywords_include or expectation.keywords_exclude:
|
||
rules.append(
|
||
EvalRuleConfig(
|
||
type="keyword_match",
|
||
params={
|
||
"keywords": expectation.keywords_include,
|
||
"exclude_keywords": expectation.keywords_exclude,
|
||
},
|
||
)
|
||
)
|
||
return rules
|