Merge pull request #2257 from BerriAI/litellm_ui_top_models

[UI] View top models by spend
This commit is contained in:
Krish Dholakia 2024-02-29 13:59:40 -08:00 committed by GitHub
commit aee004ad49
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(