Data models
Data Models Reference
This document describes the core data models used in the Reward Kit for representing messages, evaluation results, and metrics.
Message Models
Message
The Message
class represents a single message in a conversation.
Attributes
-
role
(str
): The role of the message sender. Typically one of:"user"
: Message from the user"assistant"
: Message from the assistant"system"
: System message providing context/instructions
-
content
(str
): The text content of the message. -
name
(Optional[str]
): Optional name of the sender (for named system messages). -
tool_call_id
(Optional[str]
): Optional ID for a tool call (used in tool calling). -
tool_calls
(Optional[List[Dict[str, Any]]]
): Optional list of tool calls in the message. -
function_call
(Optional[Dict[str, Any]]
): Optional function call information (legacy format).
Compatibility
The Message
class is compatible with OpenAI’s ChatCompletionMessageParam
interface, allowing for easy integration with OpenAI-compatible APIs.
Reward Output Models
RewardOutput
The RewardOutput
class represents the complete result of a reward function evaluation.
Attributes
-
score
(float
): The overall reward score, typically between 0.0 and 1.0. -
metrics
(Dict[str, MetricRewardOutput]
): Dictionary of component metrics, with metric names as keys andMetricRewardOutput
objects as values.
Methods
-
to_dict()
→Dict[str, Any]
: Converts theRewardOutput
to a dictionary representation. -
from_dict(data: Dict[str, Any])
→RewardOutput
: Class method that creates aRewardOutput
from a dictionary representation. -
__str__()
→str
: Returns a JSON string representation of theRewardOutput
.
MetricRewardOutput
The MetricRewardOutput
class represents a single component metric in a reward evaluation.
Attributes
-
score
(float
): The score for this specific metric, typically between 0.0 and 1.0. -
reason
(Optional[str]
): Optional explanation for why this score was assigned.
Evaluation Models
EvaluateResult
The EvaluateResult
class represents the complete result of an evaluator with multiple metrics.
Attributes
-
score
(float
): The overall evaluation score, typically between 0.0 and 1.0. -
reason
(Optional[str]
): Optional explanation for the overall score. -
metrics
(Dict[str, MetricResult]
): Dictionary of component metrics. -
error
(Optional[str]
): Optional error message if the evaluation encountered a problem.
MetricResult
The MetricResult
class represents a single metric in an evaluation.
Attributes
-
score
(float
): The score for this specific metric, typically between 0.0 and 1.0. -
reason
(str
): Explanation for why this score was assigned. -
success
(Optional[bool]
): Optional flag indicating whether this metric evaluation was successful.
Example Usages
Working with Messages
Working with RewardOutput
Working with EvaluateResult
Conversion Between Types
Reward Kit provides functions for converting between RewardOutput
and EvaluateResult
formats:
This conversion functionality is useful when interacting with different parts of the API that might expect different formats.
Type Compatibility
While the classes provide strong typing for development, the Reward Kit also accepts dictionary representations for flexibility:
This flexibility makes it easier to integrate with different APIs and data formats.