@reward_function
decorator and the components that make up a complete reward function.
@reward_function
Decorator@reward_function
decorator is the core mechanism that transforms a regular Python function into a reward function that can be used for evaluation and deployment.
@reward_function
decorator performs several important functions:
EvaluateResult
object.deploy()
method to the function for easy deploymentEvaluateResult
object.deploy()
methodmessages
: A list of message dictionaries in the conversation, where each message has at least "role"
and "content"
keys. The last message is typically the one being evaluated.original_messages
: The conversation context, usually messages before the response being evaluated. If not provided, it defaults to messages[:-1]
.**kwargs
: Additional parameters that can be used to customize the evaluation.EvaluateResult
object:
score
: The final aggregate score (typically between 0.0 and 1.0).reason
: An optional top-level explanation for the overall score.metrics
: A dictionary of component metrics (MetricResult
objects), each with its own score, success flag, and explanation.error
: An optional string field to convey errors during evaluation.@reward_function
decorator adds a .deploy()
method to your function:
name
: ID for the deployed evaluator (required)description
: Human-readable description (optional)force
: Whether to overwrite an existing evaluator with the same name (optional)providers
: List of model providers to use for evaluation (optional)**kwargs
parameter, often via a metadata
dictionary.