Skip to content

Commit 69d8a62

Browse files
committed
fix(playground): fix KeyError: 'carbon' in Usage page
1 parent c341c0b commit 69d8a62

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

playground/app/features/usage/state.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ async def load_entities(self):
8585
completion_tokens=u["usage"]["completion_tokens"],
8686
total_tokens=u["usage"]["total_tokens"],
8787
cost=u["usage"]["cost"],
88-
kgco2eq=u["usage"]["carbon"]["kgCO2eq"],
88+
kgco2eq=u["usage"]["impacts"]["kgCO2eq"],
8989
)
9090
for u in data.get("data", [])
9191
]
@@ -106,15 +106,17 @@ async def load_entities(self):
106106
def usage_rows(self) -> list[dict[str, Any]]:
107107
rows: list[dict[str, Any]] = []
108108
for row in self.entities:
109-
rows.append({
110-
"date": row.created,
111-
"endpoint": row.endpoint,
112-
"key": row.key,
113-
"model": row.model,
114-
"tokens": "" if row.total_tokens == 0 else f"{row.prompt_tokens}{row.completion_tokens}",
115-
"cost": "" if row.cost == 0.0 or row.cost is None else f"{row.cost:.4f}",
116-
"kgCO2eq": "" if row.kgco2eq is None else f"{round(row.kgco2eq, 5)}",
117-
})
109+
rows.append(
110+
{
111+
"date": row.created,
112+
"endpoint": row.endpoint,
113+
"key": row.key,
114+
"model": row.model,
115+
"tokens": "" if row.total_tokens == 0 else f"{row.prompt_tokens}{row.completion_tokens}",
116+
"cost": "" if row.cost == 0.0 or row.cost is None else f"{row.cost:.4f}",
117+
"kgCO2eq": "" if row.kgco2eq is None else f"{round(row.kgco2eq, 5)}",
118+
}
119+
)
118120
return rows
119121

120122
############################################################

0 commit comments

Comments
 (0)