IgorSlinko commited on
Commit
00808db
·
1 Parent(s): a75cc98

Always use Calculated data for Original Cost in routing

Browse files

Original Cost should always be calculated from the 'calculated' df
(with overhead and cache settings applied), not from metadata

Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -1528,20 +1528,18 @@ def build_app():
1528
  )
1529
  return
1530
 
1531
- df_key = "meta" if source == "Metadata" else "calculated"
1532
- df = state_data.get(df_key)
1533
- if df is not None and not df.empty:
1534
- if source == "Calculated":
1535
- df = apply_thinking_overhead(df.copy(), overhead)
1536
- if not with_cache:
1537
- df = apply_no_cache(df)
1538
- df_temp = df.copy()
1539
  df_temp["uncached_input"] = (df_temp["prompt_tokens"] - df_temp["cache_read_tokens"] - df_temp["cache_creation_tokens"]).clip(lower=0)
1540
  total_original_cost_from_df = (
1541
  df_temp["uncached_input"].sum() * base_input / 1e6 +
1542
- df["cache_read_tokens"].sum() * base_cache_read / 1e6 +
1543
- df["cache_creation_tokens"].sum() * base_cache_creation / 1e6 +
1544
- df["completion_tokens"].sum() * base_completion / 1e6
1545
  )
1546
  else:
1547
  total_original_cost_from_df = None
 
1528
  )
1529
  return
1530
 
1531
+ df_calc = state_data.get("calculated")
1532
+ if df_calc is not None and not df_calc.empty:
1533
+ df_for_cost = apply_thinking_overhead(df_calc.copy(), overhead)
1534
+ if not with_cache:
1535
+ df_for_cost = apply_no_cache(df_for_cost)
1536
+ df_temp = df_for_cost.copy()
 
 
1537
  df_temp["uncached_input"] = (df_temp["prompt_tokens"] - df_temp["cache_read_tokens"] - df_temp["cache_creation_tokens"]).clip(lower=0)
1538
  total_original_cost_from_df = (
1539
  df_temp["uncached_input"].sum() * base_input / 1e6 +
1540
+ df_for_cost["cache_read_tokens"].sum() * base_cache_read / 1e6 +
1541
+ df_for_cost["cache_creation_tokens"].sum() * base_cache_creation / 1e6 +
1542
+ df_for_cost["completion_tokens"].sum() * base_completion / 1e6
1543
  )
1544
  else:
1545
  total_original_cost_from_df = None