fix(usage.tsx): show top models by spend

This commit is contained in:
Krrish Dholakia 2024-02-29 13:10:20 -08:00
parent 524cdb74a4
commit 52ee407f50
11 changed files with 54 additions and 9 deletions

View file

@ -570,6 +570,29 @@ class PrismaClient:
print("Last30dKeysBySpend Created!") # noqa
try:
await self.db.query_raw("""SELECT 1 FROM "Last30dModelsBySpend" LIMIT 1""")
print("Last30dModelsBySpend Exists!") # noqa
except Exception as e:
sql_query = """
CREATE OR REPLACE VIEW "Last30dModelsBySpend" AS
SELECT
"model",
SUM("spend") AS total_spend
FROM
"LiteLLM_SpendLogs"
WHERE
"startTime" >= (CURRENT_DATE - INTERVAL '30 days')
AND "model" != ''
GROUP BY
"model"
ORDER BY
total_spend DESC;
"""
await self.db.execute_raw(query=sql_query)
print("Last30dModelsBySpend Created!") # noqa
return
@backoff.on_exception(