Skip to content

Commit 2b49af7

Browse files
committed
Add field to track time to first response and token usages
1 parent ab55d7e commit 2b49af7

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎evalbench/eval_service.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""A gRPC servicer that handles EvalService requests."""
22

3+
import ast
34
import asyncio
45
import json
56
import os
7+
import pandas as pd
68
from collections.abc import AsyncIterator
79
from typing import AsyncGenerator
810

@@ -514,4 +516,31 @@ def _process_results(
514516
"p90": round(latencies.quantile(0.9), 2),
515517
}
516518

519+
# Add percentiles for metrics reported via the `other` map. `other` is
520+
# stored as a string-serialized dict in the dataframe, so parse it first.
521+
if "other" in results_df.columns:
522+
def _parse_other(o):
523+
if isinstance(o, dict):
524+
return o
525+
if isinstance(o, str) and o:
526+
try:
527+
return ast.literal_eval(o)
528+
except (ValueError, SyntaxError):
529+
return {}
530+
return {}
531+
532+
parsed_other = results_df["other"].apply(_parse_other)
533+
for metric_key in (
534+
"time_to_first_response",
535+
"input_token_count",
536+
"output_token_count",
537+
):
538+
values = parsed_other.apply(lambda d, k=metric_key: d.get(k))
539+
values = pd.to_numeric(values, errors="coerce").dropna()
540+
if not values.empty:
541+
summary[metric_key] = {
542+
"p50": round(values.quantile(0.5), 2),
543+
"p90": round(values.quantile(0.9), 2),
544+
}
545+
517546
return summary

0 commit comments

Comments
 (0)