File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11"""A gRPC servicer that handles EvalService requests."""
22
3+ import ast
34import asyncio
45import json
56import os
7+ import pandas as pd
68from collections .abc import AsyncIterator
79from 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
You can’t perform that action at this time.
0 commit comments