RewardFunction
class is a core component of the Reward Kit, providing a unified interface for calling reward functions locally or remotely.
RewardFunction
class wraps a reward function (either a local function or a remote endpoint) and provides a consistent interface for evaluation. It supports:
func
(Optional[Callable]
): The local function to use (for mode=“local”).
func_path
(Optional[str]
): A string path to a function (e.g., “module.submodule:function_name”).
mode
(str
): The mode of operation. Options:
"local"
: Run the function locally"remote"
: Call a remote endpoint"fireworks_hosted"
: Use a Fireworks-hosted modelendpoint
(Optional[str]
): The URL of the remote endpoint (for mode=“remote”).
name
(Optional[str]
): The name of the deployed evaluator (for mode=“remote”).
If provided and endpoint is not, the endpoint will be constructed from the name.
model_id
(Optional[str]
): The ID of the Fireworks-hosted model (for mode=“fireworks_hosted”).
**kwargs
: Additional keyword arguments to pass to the function when called.
ValueError
: Raised if required parameters for the specified mode are missing or if an invalid mode is provided.__call__
messages
(List[Dict[str, str]]
): List of conversation messages, each with ‘role’ and ‘content’ keys.
original_messages
(Optional[List[Dict[str, str]]]
): Original conversation messages (for context).
Defaults to all messages except the last one if not provided.
**kwargs
: Additional keyword arguments to pass to the function.
EvaluateResult
: Object with score and metrics.ValueError
: Raised if no function or endpoint is provided for the selected mode.TypeError
: Raised if the function returns an invalid type.requests.exceptions.RequestException
: Raised if there is an error calling the remote endpoint.get_trl_adapter
Callable
: A function that takes batch inputs and returns a batch of reward values, compatible with TRL.func
or func_path
.endpoint
or name
.model_id
.func_path
, the path can be specified in two formats:
module.path:function_name
- Module with colon separator (preferred)module.path.function_name
- Module with function as last componentFIREWORKS_API_KEY
environment variable.