flexeval.compute_metrics#
Utilities for computing needed metric computations and actually invoking those computations.
Functions
Adds all metric instances in metrics_for_level to each instance of an evaluable object (e.g., Turn, Thread, Message, or ToolCall) in iterable_of_objects. |
|
|
|
|
Returns the total number of rubric type metrics in the metrics_to_evaluate field in each object. |
Classes
|
|
Builds |
|
|
- class flexeval.compute_metrics.MetricComputer(function_modules: list, evalsetrun: EvalSetRun | None = None)[source]#
Bases:
object- compute_function_metric(function_name: str, metric_kwargs: dict, input_object: Thread | Turn | Message | ToolCall, metric_level: Literal['Message', 'Turn', 'Thread', 'ToolCall'], depends_on: list, id: int)[source]#
- compute_metric(object: Thread | Turn | Message | ToolCall, evaluation_name: str, evaluation_type: str, metric_level: str, kwargs: dict, depends_on: list | None = None, id: int | None = None, notes: str | None = None) list[dict][source]#
- compute_metrics(object: Thread | Turn | Message | ToolCall)[source]#
we’ve defined a variable called metrics_to_evaluate it’s a list we need to loop through each entry looks like this {
‘name’: ‘string_length’, ‘type’: ‘function’, ‘kwargs’: {}, ‘depends_on’: []
}
- compute_rubric_metric(rubric_name: str, metric_kwargs: dict, object: Thread | Turn | Message, metric_level: str, depends_on: list, id: int)[source]#
- classmethod from_evalrun(evalrun: EvalRun, evalsetrun: EvalSetRun | None = None) MetricComputer[source]#
- invoke_function(metric_function: callable, metric_level: Literal['Message', 'Turn', 'Thread', 'ToolCall'], input_object: Turn | Message | Thread | ToolCall, metric_kwargs: dict)[source]#
- load_rubrics(evalsetrun: EvalSetRun) dict[source]#
Load and return rubrics from the given EvalSetRun.
- class flexeval.compute_metrics.MetricGraphBuilder[source]#
Bases:
objectBuilds
networkx.DiGraphs ofObjectMetricinstances that reflect any computational dependencies between them.- build_metric_structures(evalsetrun: EvalSetRun)[source]#
- find_object_metric_from_depends_on(current_object: Message | Turn | ToolCall | Thread, current_metric_level: Literal['Message', 'Turn', 'Thread', 'ToolCall'], current_index: int, depends_on: dict) ObjectMetric | None[source]#
If you’re a Turn metric that depends on a Message metric, then we create a dependency on ALL or ANY Message meeting the criteria. We don’t know how to handle that…
In contrast, if you’re a Message metric that depends on a Turn metric, then we have a dependency on only a single object: that Message’s Turn.
- class flexeval.compute_metrics.ObjectMetric(object: Message | Turn | ToolCall | Thread, metric: dict)[source]#
Bases:
object
- flexeval.compute_metrics.add_all_metrics_to_objects(iterable_of_objects, metrics)[source]#
Adds all metric instances in metrics_for_level to each instance of an evaluable object (e.g., Turn, Thread, Message, or ToolCall) in iterable_of_objects. This addition is done by appending to the metrics_to_evaluate field, which all instances in iterable_of_objects should have.
- Parameters:
iterable_of_objects – list of objects that have a metrics_to_evaluate field
metrics – list of metric instances to add to each object