File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change 3333import statistics
3434
3535
36+ logger = logging .getLogger (__name__ )
37+
3638AggregationMethod = Literal ["mean" , "max" , "min" , "bootstrap" ]
3739
3840
@@ -495,10 +497,18 @@ def add_cost_metrics(row: EvaluationRow) -> None:
495497 input_tokens = usage .prompt_tokens or 0
496498 output_tokens = usage .completion_tokens or 0
497499
498- input_cost , output_cost = cost_per_token (
499- model = model_id , prompt_tokens = input_tokens , completion_tokens = output_tokens
500- )
501- total_cost = input_cost + output_cost
500+ # Try to calculate costs, but gracefully handle unknown models
501+ try :
502+ input_cost , output_cost = cost_per_token (
503+ model = model_id , prompt_tokens = input_tokens , completion_tokens = output_tokens
504+ )
505+ total_cost = input_cost + output_cost
506+ except Exception as e :
507+ # Model not in LiteLLM's database - set costs to 0 and continue
508+ logger .debug (f"Could not calculate cost for model '{ model_id } ': { e } " )
509+ input_cost = 0.0
510+ output_cost = 0.0
511+ total_cost = 0.0
502512
503513 # Set all cost metrics on the row
504514 row .execution_metadata .cost_metrics = CostMetrics (
You can’t perform that action at this time.
0 commit comments