Commit
·
00808db
1
Parent(s):
a75cc98
Always use Calculated data for Original Cost in routing
Browse filesOriginal Cost should always be calculated from the 'calculated' df
(with overhead and cache settings applied), not from metadata
app.py
CHANGED
|
@@ -1528,20 +1528,18 @@ def build_app():
|
|
| 1528 |
)
|
| 1529 |
return
|
| 1530 |
|
| 1531 |
-
|
| 1532 |
-
|
| 1533 |
-
|
| 1534 |
-
if
|
| 1535 |
-
|
| 1536 |
-
|
| 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 |
-
|
| 1543 |
-
|
| 1544 |
-
|
| 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
|