Skip to content

Commit 08d43e1

Browse files
committed
feat(eval): introduce the limit for heatmap api
1 parent b92463a commit 08d43e1

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

services/budapp/budapp/eval_ops/eval_routes.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,18 +719,24 @@ def get_heatmap_chart_data(
719719
Optional[datetime],
720720
Query(description="Filter runs before this date (ISO 8601)"),
721721
] = None,
722+
limit: Annotated[
723+
int,
724+
Query(ge=1, le=50, description="Maximum number of deployments to return (default: 5)"),
725+
] = 5,
722726
):
723727
"""Get heatmap chart data for comparing deployments across datasets.
724728
725729
Returns dataset benchmark scores for each selected deployment. Scores
726730
represent the average accuracy across all completed evaluation runs for
727-
each dataset-deployment combination.
731+
each dataset-deployment combination. By default, returns only the 5 most
732+
recent deployments with successful runs.
728733
729734
- **deployment_ids**: Optional comma-separated deployment UUIDs to compare. Returns all if not provided.
730735
- **trait_ids**: Optional comma-separated trait UUIDs to filter datasets.
731736
- **dataset_ids**: Optional comma-separated dataset UUIDs to filter.
732737
- **start_date**: Optional filter for runs after this date.
733738
- **end_date**: Optional filter for runs before this date.
739+
- **limit**: Maximum number of deployments to return (default: 5, max: 50).
734740
735741
Returns a `HeatmapChartResponse` with:
736742
- List of datasets (columns for the heatmap)
@@ -783,6 +789,7 @@ def get_heatmap_chart_data(
783789
dataset_ids=dataset_id_list,
784790
start_date=start_date,
785791
end_date=end_date,
792+
limit=limit,
786793
)
787794

788795
return HeatmapChartResponse(

services/budapp/budapp/eval_ops/services.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3123,18 +3123,21 @@ def get_heatmap_chart_data(
31233123
dataset_ids: Optional[List[uuid.UUID]] = None,
31243124
start_date: Optional[datetime] = None,
31253125
end_date: Optional[datetime] = None,
3126+
limit: int = 5,
31263127
) -> Dict[str, Any]:
31273128
"""Get heatmap chart data showing dataset scores per deployment.
31283129
31293130
For each deployment, calculates average scores per dataset.
31303131
Returns a matrix of deployment x dataset with average accuracy scores.
3132+
By default, returns only the 5 most recent deployments with successful runs.
31313133
31323134
Parameters:
31333135
deployment_ids (Optional[List[uuid.UUID]]): List of deployment/endpoint IDs. If None, returns all.
31343136
trait_ids (Optional[List[uuid.UUID]]): Filter datasets by traits.
31353137
dataset_ids (Optional[List[uuid.UUID]]): Filter by specific datasets.
31363138
start_date (Optional[datetime]): Filter runs after this date.
31373139
end_date (Optional[datetime]): Filter runs before this date.
3140+
limit (int): Maximum number of deployments to return (default: 5).
31383141
31393142
Returns:
31403143
Dict containing:
@@ -3152,6 +3155,7 @@ def get_heatmap_chart_data(
31523155
DatasetModel.id.label("dataset_id"),
31533156
DatasetModel.name.label("dataset_name"),
31543157
MetricModel.metric_value,
3158+
RunModel.created_at.label("run_created_at"),
31553159
)
31563160
.join(EndpointModel, RunModel.endpoint_id == EndpointModel.id)
31573161
.join(ModelTable, EndpointModel.model_id == ModelTable.id)
@@ -3212,7 +3216,15 @@ def get_heatmap_chart_data(
32123216
"deployment_name": row.endpoint_name,
32133217
"model_name": row.model_name,
32143218
"dataset_scores": {}, # {dataset_id: {"scores": [], "run_count": int}}
3219+
"latest_run_at": row.run_created_at,
32153220
}
3221+
else:
3222+
# Track the latest run timestamp for this deployment
3223+
if row.run_created_at and (
3224+
deployments_data[endpoint_id]["latest_run_at"] is None
3225+
or row.run_created_at > deployments_data[endpoint_id]["latest_run_at"]
3226+
):
3227+
deployments_data[endpoint_id]["latest_run_at"] = row.run_created_at
32163228

32173229
# Track scores per dataset
32183230
if dataset_id not in deployments_data[endpoint_id]["dataset_scores"]:
@@ -3229,8 +3241,15 @@ def get_heatmap_chart_data(
32293241
# Calculate averages and build response
32303242
datasets_list = list(datasets_data.values())
32313243

3244+
# Sort deployments by latest run timestamp (descending) and apply limit
3245+
sorted_deployments = sorted(
3246+
deployments_data.items(),
3247+
key=lambda x: x[1]["latest_run_at"] or datetime.min,
3248+
reverse=True,
3249+
)[:limit]
3250+
32323251
deployments_list = []
3233-
for _endpoint_id, data in deployments_data.items():
3252+
for _endpoint_id, data in sorted_deployments:
32343253
dataset_scores = []
32353254
for dataset_id, score_data in data["dataset_scores"].items():
32363255
scores = score_data["scores"]

0 commit comments

Comments
 (0)